自动化进阶

一、python邮件发送

import smtplib  # 发送邮件模块
from email.mime.text import MIMEText  # 定义邮件内容
from email.header import Header  # 定义邮件标题

# 发送邮箱服务器
smtpserver = "smtp.163.com"

# 发送邮箱用户名密码
username = "[email protected]"
password = "LIna2014"

# 发送和接收邮箱
sender = "[email protected]"
receive = "[email protected]"

#发送邮件主题和内容
subject = "Web Selenium 自动化测试报告"
content = '<html><h1 style="color:red">我要自学网,自学成才</h1></html>'

#HTML邮件正文
msg = MIMEText(content, 'html', 'utf-8')
msg['Subject'] = Header(subject, 'utf-8')
msg['From'] = '[email protected]'
msg['To'] = '[email protected]'

#SSL协议端口使用465
smtp = smtplib.SMTP_SSL(smtpserver, 465)
#向服务器标适识用户身份
smtp.helo(smtpserver)
#服务器返回结果确认
smtp.ehlo(smtpserver)
#登录邮箱服务器用户名和密码
smtp.login(username, password)

print("Start send Email...")
smtp.sendmail(sender, receive, msg.as_string())
smtp.quit()
print("Send Email end")

猜你喜欢

转载自www.cnblogs.com/xidian2014/p/10425002.html