当前位置: 移动技术网 > IT编程>脚本编程>Python > 用python SMTP进行邮件发送

用python SMTP进行邮件发送

2019年01月14日  | 移动技术网IT编程  | 我要评论

排球女将高清,安徽贪官,萨比诺的气阀

 1 import  smtplib
 2 from email.mime.text import mimetext
 3 from email.mime.multipart import mimemultipart
 4 """多用户及带附件发送邮件代码"""
 5 
 6 smtpserver = 'smtp.163.com' #发送邮箱服务器
 7 
 8 user = 'a5974939632@163.com'
 9 password = 'wang1989'
10 
11 sender = 'a5974939632@163.com'
12 receive = ['a5974939632@126.com', 'a5974939632@163.com']
13 
14 subject = 'web selenium 自动化测试报告'
15 content = '<html><h1 style="color:red">我要自学网,自学成才!</h1></html>'
16 
17 send_file = open(r'e:\study\seleniumpython\unittest\test_baidu\test_report\2019-01-08 12_00_24result.html','rb').read()
18 
19 att = mimetext(send_file, 'base64', 'utf-8')
20 att['content-type'] = 'application/octet-stream'
21 att['content-disposition'] = 'attachment:filename="2019-01-08 12_00_24result.html"'
22 
23 msgroot = mimemultipart()
24 msgroot.attach(mimetext(content, 'html', 'utf-8'))
25 msgroot['subject'] = subject
26 msgroot['from'] = sender
27 msgroot['to'] = ','.join(receive)
28 msgroot.attach(att)
29 
30 smtp = smtplib.smtp_ssl(smtpserver,465)
31 smtp.helo(smtpserver)
32 smtp.ehlo(smtpserver)
33 smtp.login(user,password)
34 
35 print("start send email...")
36 smtp.sendmail(sender,receive,msgroot.as_string())
37 smtp.quit()
38 print("send email end!")

 

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

相关文章:

验证码:
移动技术网