我发现此代码可以向多个收件人发送电子邮件:
import smtplib
from email.mime.text import MIMEText
s = smtplib.SMTP('smtp.uk.xensource.com')
s.set_debuglevel(1)
msg = MIMEText("""body""")
sender = 'me@example.com'
recipients = ['john.doe@example.com', 'john.smith@example.co.uk']
msg['Subject'] = "subject line"
msg['From'] = sender
msg['To'] = ", ".join(recipients)
s.sendmail(sender, recipients, msg.as_string())
但我想使用我所拥有的文本文件更改收到每封电子邮件的人的姓名。
答案 0 :(得分:0)
您有多种选择:
在第三个选项中,您的代码如下所示:
file = open("receipients.txt", "r")
receipients = file.readlines():
...