2012-01-04 66 views
5

我想知道。有没有办法在其默认的SMTPlib中添加Python中的多个接收器?有没有办法在Python SMTPlib中添加多个接收器?

赞(主题和内容已经集,SMTP服务器使用Gmail。):

python sendmail.py [email protected] [email protected] [email protected] ... 

感谢

+0

可能重复[如何使用Python的smtplib发送电子邮件给多个收件人?(http://stackoverflow.com/questions/8856117/how-to-send-email-to-multiple-recipients-using -python-的smtplib) – 2015-05-20 09:04:26

回答

3

docs

发送邮件。所需的参数是RFC 822来自地址字符串, RFC 822至地址字符串列表(一个裸空字符串将被视为 带有1个地址的列表)和一个消息字符串。

6

发布之前经过测试!

import smtplib 
from email.mime.text import MIMEText 

s = smtplib.SMTP('smtp.uk.xensource.com') 
s.set_debuglevel(1) 
msg = MIMEText("""body""") 
sender = '[email protected]' 
recipients = ['[email protected]', '[email protected]'] 
msg['Subject'] = "subject line" 
msg['From'] = sender 
msg['To'] = ", ".join(recipients) 
s.sendmail(msg.get('From'), recipients, msg.as_string()) 
相关问题