def SendMail(newfile):
f=open(newfile,'rb')
mail_body=f.read()
f.close()
smtpserver = 'smtp.QQ.com'
user = 'user@qq.com'
password = '密码'
sender="user@qq.com"
receiver=["user@qq.com"] #群发以逗号隔开 加上对应邮箱名 即可
subject='自动化测试报告'
msg
= MIMEMultipart
(
'mixed'
)
msg_html1
= MIMEText
(mail_body,
'html',
'utf-8'
)
msg.attach
(msg_html1
)
msg_html
= MIMEText
(mail_body,
'html',
'utf-8'
)
msg_html
[
"Content-Disposition"
] =
'attachment;filename="result.html"'
msg.attach
(msg_html
)
msg
[
'From'
] =
'user@qq.com'#发送方
msg['To'] = ";".join(receiver)
msg
[
'Subject'
] = Header
(subject,
'utf-8'
)
smtp
= smtplib.SMTP
()
smtp.connect
(smtpserver,
25
)
smtp.login
(user, password
)
smtp.sendmail
(sender, receiver, msg.as_string
())
smtp.quit
()
安装对应 插件 切记 不要图快
productResult.SendMail(new_repor)
我是放在类里面的 所以要调用的话的实例