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()

 

 

posted @ 2019-02-18 11:39  OTAKU_nicole  阅读(793)  评论(0编辑  收藏  举报