import sys
import datetime
me = sys.argv[1]
you = sys.argv[2] #[I want to pass here multiple recipient]
subject = datetime.now().strftime("%I %P")
# Create the root message and fill in the from, to, and subject headers
msgRoot = MIMEMultipart('related')
msgRoot['Subject'] = 'Status Update ' + str(subject)
msgRoot['From'] = me
msgRoot['To'] = you
#msgRoot['To'] = ",".join(you)
"""Earlier I was using something like above when I was hardcoding email address insided it"""
如果我需要使用toaddr
传递多个收件人的sys.argv
,请问有人可以建议我使用哪种最佳方法?
答案 0 :(得分:0)
使用", "
(逗号和空格)和命令行参数切片来加入所有地址
msgRoot['To'] = ", ".join(sys.argv[2:])
(改编自How to send email to multiple recipients using python smtplib?)