我很难相信以前没有人问过这个问题,但我找不到回答这个问题的stackoverflow。
编辑:
这个问题不是
How to send email to multiple recipients
,这是怎么做的,但是
没有
其他收件人能够看到其他收件人的电子邮件。
如何生成一封电子邮件并分别发送给多个收件人?
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()
但是重新分配
['To']
的
message
导致此错误的原因:
ValueError: There may be at most 1 To headers in a message
我做错了什么?有没有一种更简单的方法可以在不重建电子邮件的情况下分别发送给多个收件人?