当前位置: 移动技术网 > IT编程>脚本编程>Python > python自动发送测试报告(五)

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

2018年05月31日  | 移动技术网IT编程  | 我要评论

砀山天气预报,多功能限位器,王自如二手手机

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

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

代码如下:

 1 #!/usr/bin/python
 2 # -*- coding: UTF-8 -*-
 3 
 4 import smtplib
 5 from email.mime.multipart import MIMEMultipart
 6 from email.mime.application import MIMEApplication
 7 
 8 smtp_server = 'smtp.163.com'
 9 sender = 'SunshineWuya@163.com'
10 pwd = 'xxxx'
11 
12 txt = MIMEMultipart()
13 txt['Subject'] = '自动化测试报告'
14 txt['From'] = sender
15 
16 # 上传附件
17 part = MIMEApplication(open('/Users/ydj/Desktop/微信后台测试.html','rb').read())
18 part.add_header('Content-Disposition', 'attachment', filename=('utf-8','','微信后台测试.html'))
19 txt.attach(part)
20 
21 mail_server = smtplib.SMTP(smtp_server,25)
22 mail_server.login(sender,pwd)
23 mail_server.sendmail(sender,['SunshineWuya@163.com'],txt.as_string())
24 
25 mail_server.quit()

结果如下:

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网