电子邮件仅发送给第一个收件人SMTP邮件python [英] Email goes to first recipient only smtp mail python
问题描述
我知道,同一查询有数百个问题。为此事道歉。我几乎尝试了每个。但是仍然没有得到解决方案。实际上,我从stackoverflow查询之一复制了一些代码,并根据我的要求对其进行了改进。
I know, There are hundreds of questions with the same query. Sorry about this. I tried almost each of them. But still did not get the solution. In fact, I copied some of the code from one of stackoverflow query and improved it as per my requirement.
我正在编写一个脚本,使用python为我们的一台服务器发送错误报告。我的问题是电子邮件仅发送给RECIPIENTS的第一位成员。
它需要一次发送给经理团队以及管理员。
I'm writing a script to send error report using python for one of our server. My problem is Email is sending to first member of RECIPIENTS only.
It needs to be send to the team of managers as well as to the admins at a time.
RECIPIENTS = ["mail1@gmail.com", 'mail2@mydomain.in' ]
TO = ", ".join(RECIPIENTS)
USER = "user30@gmail.com"
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()
注意:-所有提到的功能和模块都正确导入了 c。实际上,它可以成功发送邮件。
Note :- All the mentioned functions and modules are import
ed properly. In fact, it sends mail successfully.
我尝试了以下旧帖子:
- 如何使用python smtplib将电子邮件发送给多个收件人?
- SMTP已将邮件发送给许多收件人,但没有收到
- 使用Python smtplib将电子邮件从.txt文件发送到多个收件人
- 为什么我不能使用此脚本向多个收件人发送电子邮件?和
- 更多
- How to send email to multiple recipints using python smtplib?
- SMTP sent mail to many recipients but doesn't received it
- Send Email to multiple recipients from .txt file with Python smtplib
- Why can't I send emails to multiple recipients with this script? and
- many more
推荐答案
要将电子邮件发送给多个人,您需要在sendmail函数中传递列表而不是字符串。
To send the email to multiple people you need to pass a list not string in sendmail function. This will work fine for you.
try:
SERVER.sendmail(msg['From'], RECIPIENTS, msg.as_string())
except Exception, e:
logit(e)
return False
这篇关于电子邮件仅发送给第一个收件人SMTP邮件python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!