我知道,同一个查询有数百个问题。为此事道歉。我几乎每一个都尝试过。但仍然没有得到解决方案。事实上,我从 stackoverflow 查询之一复制了一些代码,并根据我的要求对其进行了改进。
我正在编写一个脚本,使用 python 为我们的一台服务器发送错误报告。我的问题是Email is sending to first member of RECIPIENTS only.
它需要一次发送给经理团队和管理员。
RECIPIENTS = ["[email protected] /cdn-cgi/l/email-protection", '[email protected] /cdn-cgi/l/email-protection' ]
TO = ", ".join(RECIPIENTS)
USER = "[email protected] /cdn-cgi/l/email-protection"
PASSWD = "userpass"
def sendmail():
msg = MIMEMultipart('alternative')
msg['Subject'] = subject()
msg['From'] = USER
msg['To'] = TO
mime_text = MIMEText(get_msg_text(), 'plain')
msg.attach(mime_text)
#-- Auth by Gmail
SERVER = smtplib.SMTP("smtp.gmail.com:587")
SERVER.starttls()
try:
SERVER.login(USER,PASSWD)
except SMTPAuthenticationError, e:
logit(e)
return False
try:
SERVER.sendmail(msg['From'], msg['To'], msg.as_string())
except Exception, e:
logit(e)
return False
finally:
SERVER.quit()
return True
if __name__ == "__main__":
sendmail()
Note:- 所有提到的功能和模块都是import
正确编辑。事实上,邮件发送成功了。
我尝试遵循旧帖子:
-
如何使用 python smtplib 向多个收件人发送电子邮件? https://stackoverflow.com/questions/8856117/how-to-send-email-to-multiple-recipints-using-python-smtplib
-
SMTP 向许多收件人发送了邮件但没有收到邮件 https://stackoverflow.com/questions/11745171/smtp-sent-mail-to-many-recipients-but-doesnt-received-it
-
使用 Python smtplib 从 .txt 文件向多个收件人发送电子邮件 https://stackoverflow.com/questions/6941811/send-email-to-multiple-recipients-from-txt-file-with-python-smtplib
-
为什么我无法使用此脚本向多个收件人发送电子邮件? https://stackoverflow.com/questions/8995445/why-cant-i-send-emails-to-multiple-recipients-with-this-script and
要将电子邮件发送给多人,您需要在 sendmail 函数中传递列表而不是字符串。这对你来说效果很好。
try:
SERVER.sendmail(msg['From'], RECIPIENTS, msg.as_string())
except Exception, e:
logit(e)
return False
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)