作者:百变精灵621126 | 来源:互联网 | 2023-09-12 17:17
importsmtplibfromemail.headerimportHeaderfromemail.mime.textimportMIMETextdefsend_mail(rec
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()