python标准库smtplib在UI自动化测试中的实现-邮件发送测试报告


import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart


def
send_email(receiver): ''' 发送最新的测试报告 :return: ''' # 打开测试报告 with open(reportfile, "rb") as f: email_body = f.read() # 定义邮件内容 message = MIMEMultipart() body = MIMEText(_text=test, _subtype='html', _charset='utf-8') message['Subject'] = u"多媒体自动化测试报告_{}".format(times) message["from"] = sender message["to"] = receiver message.attach(body) # 添加附件 attachment = MIMEText(_text=email_body, _subtype='base64', _charset='utf-8)') attachment["Content-Type"] = "application/octet-stream" attachment["Content-Disposition"] = 'attachment; filename= "report.html"' message.attach(attachment) try: smtp = smtplib.SMTP_SSL(smtpserver, port) except: smtp = smtplib.SMTP() smtp.connect(smtpserver, port) # 发送邮件 smtp.login(sender, psw) smtp.sendmail(sender, receiver, message.as_string()) # 关闭邮件 smtp.quit()

 

posted @ 2020-07-02 17:29  mikigo  阅读(210)  评论(0编辑  收藏  举报