【发布时间】:2019-07-30 03:23:05
【问题描述】:
我是 python 新手,下面是假设将邮件发送到多个收件人但只有 dipeshyog94@gmail.com 收到邮件的代码。 milanthapa898@gmail.com 在 To 上排名第二,在 cc 上的 alexlee94@gmail.com 没有收到邮件
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
from email import encoders
import smtplib
owner_emp_id_email = "dipeshyogi94@gmail.com,milanthapa989@gmail.com"
mymail='milanthapa898@gmail.com'
msg = MIMEMultipart()
msg['From'] = mymail
msg['To'] = owner_emp_id_email
cc_mail = "alexlee94@gmail.com"
msg['Cc'] = cc_mail
print('####44444444444444########\n')
print(owner_emp_id_email)
msg['Subject'] = 'Automated Test Mail with python'
a = 'Milan Thapa'
#body = 'Dear '+spoc_name+',\n\nYou have created new job with below Details:\n\nProject ID : '+project_ID+'\n\nProject Name : '+ibu_name+'\n\nJob Description : ' +job_description +'\n\nThanks and Regards,\n\nMilan Thapa'
html = """\
<html>
<head></head>
<body>
<p>'Dear <b>{}<b>
</p>
</body>
</html>
""".format(a)
msg.attach(MIMEText(html,'html'))
text = msg.as_string()
try:
server = smtplib.SMTP('smtp.gmail.com:587')
except:
server = smtplib.SMTP('smtp.gmail.com:587')
server.ehlo()
server.starttls()
server.ehlo()
server.login(mymail,'password')
server.sendmail(mymail,owner_emp_id_email,text)
server.quit()
我被困在无法将邮件发送给多个用户。
任何帮助将不胜感激!
提前致谢
【问题讨论】:
-
如果这些是真实的电子邮件地址,以这样的方式公开它们几乎肯定会增加您的垃圾邮件负载。也许edit你的问题是用
mail1@example.com等占位符替换它们
标签: python python-3.x email