I'm struggling to believe this hasn't been asked before, but I couldn't find the stackoverflow where this has been answered.
Edit: This question is not How to send email to multiple recipients, this is how to do that but without the other recipients being able to see the other recipients' emails.
How could you build one EmailMessage and send it to multiple recipients SEPARATELY?
For example, I hoped you could do it like this:
import smtplib
from email.message import EmailMessage
recipients = ['recipient1@example.com', 'recipient2@example.com']
message = EmailMessage()
message['From'] = 'test@example.com'
message.set_content('You should not be able to see anyone else email')
s = smtplib.SMTP(host, port)
for recipient in recipients:
message['To'] = recipient
s.send_message(message)
s.quit()
but re-assigning the ['To'] of the message results in this error:
ValueError: There may be at most 1 To headers in a message
What am I doing wrong, and is there an easier way to send to multiple recipients separately WITHOUT rebuilding the email?