python自动化测试——发送邮件
import smtplib from email.header import Header from email.mime.text import MIMEText def send_mail(receiver = '***@qq.com'): # 邮件服务器 smtpserver = 'smtp.163.com' # 发件人和密码 sender = '***@163.com' password = '******' # 接收人 receiver = receiver # 邮件主题 subject = u'自动化测试报告' # ---------------------------------------------------------- # 连接登录邮箱 server = smtplib.SMTP(smtpserver, 25) server.login(sender, password) # ---------------------------------------------------------- msg = MIMEText("正文内容","plain",'utf-8') msg['From'] = sender msg['To'] = receiver msg['Subject'] = Header(subject, 'utf-8').encode() # ---------------------------------------------------------- # 发送邮件 server.sendmail(sender, [receiver], msg.as_string()) server.quit() print("发送成功!") send_mail()
本文来自博客园,作者:OTAKU_nicole,转载请注明原文链接:https://www.cnblogs.com/nicole-zhang/p/10394621.html