Python发送邮件

实现自动化测试,想要实现测试完成后,把测试结果自动发送一份邮件,可以通过Python的smtplib模块实现。
具体实现代码如下:
import smtplib
from email.mime.text import MIMEText
email_host='smtp.163.com' #邮箱地址
email_user='xxx@163.com' #发送者账号
email_pwd='***' #发送者密码
maillist='xxx@xx.com' #收件人邮箱,多个用逗号隔开
me=email_user
msg=MIMEText('邮件发送的内容') #邮件内容
msg['Subject']='邮件主题' #邮件主题
msg['From']=email_user
msg['To']=maillist
smtp=smtplib.SMTP(email_host,port=25)#连接邮箱,smtp端口号为25
smtp.login(email_user,email_pwd) #发送者的邮箱账号,密码
smtp.sendmail(me,maillist,msg.as_string())# 参数分别是发送者,接收者,第三个是把上面的发送邮件的内容变成字符串
smtp.quit() # 发送完毕后退出smtp
print('email send success.')
原文地址:https://www.cnblogs.com/zhuyue1/p/6203707.html