Is there any way to add multiple receivers in Python SMTPlib?

情到浓时终转凉″ 提交于 2019-12-17 20:25:12

问题


I was wondering. Is there any way to add multiple receivers in Python on its default SMTPlib?

Like (subject and content set already, smtp server gmail.):

python sendmail.py receiver1@gmail.com receiver2@gmail.com receiver3@gmail.com ...

Thanks


回答1:


Tested before posting!

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())



回答2:


From the docs:

Send mail. The required arguments are an RFC 822 from-address string, a list of RFC 822 to-address strings (a bare string will be treated as a list with 1 address), and a message string.



来源:https://stackoverflow.com/questions/8729071/is-there-any-way-to-add-multiple-receivers-in-python-smtplib

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!