import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
"""多用户及带附件发送邮件代码"""
smtpserver = 'smtp.163.com' #发送邮箱服务器
user = '***@163.com'
password = '密码'
sender = 'a5974939632@163.com'
receive = ['接收邮箱1', '接收邮箱2']
subject = 'Web Selenium 自动化测试报告'
content = '<html><h1 style="color:red">我要自学网,自学成才!</h1></html>'
send_file = open(r'E:\study\SeleniumPython\UnitTest\Test_Baidu\test_report\2019-01-08 12_00_24result.html','rb').read()
att = MIMEText(send_file, 'base64', 'utf-8')
att['Content-Type'] = 'application/octet-stream'
att['Content-Disposition'] = 'attachment:filename="2019-01-08 12_00_24result.html"'
msgRoot = MIMEMultipart()
msgRoot.attach(MIMEText(content, 'html', 'utf-8'))
msgRoot['Subject'] = subject
msgRoot['From'] = sender
msgRoot['To'] = ','.join(receive)
msgRoot.attach(att)
smtp = smtplib.SMTP_SSL(smtpserver,465)
smtp.helo(smtpserver)
smtp.ehlo(smtpserver)
smtp.login(user,password)
print("start send Email...")
smtp.sendmail(sender,receive,msgRoot.as_string())
smtp.quit()
print("send email end!")