我在想。有没有办法在Python的默认SMTPlib上添加多个接收器?
喜欢(主题和内容已经设置,smtp服务器gmail。):
python sendmail.py receiver1@gmail.com receiver2@gmail.com receiver3@gmail.com ...
由于
答案 0 :(得分:6)
发布前经过测试!
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(msg.get('From'), recipients, msg.as_string())
答案 1 :(得分:3)
来自docs:
发送邮件。必需参数是RFC 822 from-address字符串, RFC 822到地址字符串的列表(裸字符串将被视为 一个包含1个地址的列表)和一个消息字符串。