有没有办法在Python SMTPlib中添加多个接收器?

2024-04-28 21:36:03 发布

您现在位置:Python中文网/ 问答频道 /正文

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

比如(主题和内容已经设置好,smtp服务器gmail.):

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

谢谢


Tags: py服务器com内容主题smtpgmailsendmail
2条回答

发布前测试!

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

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.

相关问题 更多 >