python自动发送测试报告(五)

时间:2023-03-10 00:48:59
python自动发送测试报告(五)

python实现自动发送邮件具体步骤参考笔者的另一篇博文,python实现邮件的发送

本次只展示发送附件的代码,MIMEApplication支持常用格式文档(.jpg、.mp3、zip等)当做附件上传

代码如下:

 #!/usr/bin/python
# -*- coding: UTF-8 -*- import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.application import MIMEApplication smtp_server = 'smtp.163.com'
sender = 'SunshineWuya@163.com'
pwd = 'xxxx' txt = MIMEMultipart()
txt['Subject'] = '自动化测试报告'
txt['From'] = sender # 上传附件
part = MIMEApplication(open('/Users/ydj/Desktop/微信后台测试.html','rb').read())
part.add_header('Content-Disposition', 'attachment', filename=('utf-8','','微信后台测试.html'))
txt.attach(part) mail_server = smtplib.SMTP(smtp_server,25)
mail_server.login(sender,pwd)
mail_server.sendmail(sender,['SunshineWuya@163.com'],txt.as_string()) mail_server.quit()

结果如下:

python自动发送测试报告(五)

python自动发送测试报告(五)