• python邮件发送自动化测试报告


    话不多说直接贴代码

    # encoding: utf-8
    import smtplib #发送邮件模块
    from email.mime.text import MIMEText #邮件内容
    from email.header import Header



    def send_email(new_reportfile):
    """发送邮件"""
    f = open(new_reportfile,'rb')
    mail_content = f.read()
    f.close()

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

    # 用户名密码
    user = 'ye_songqiao123@163.com'
    password = '你的密码or授权码'

    # 发送和接收邮箱用户
    sender = 'ye_songqiao123@163.com'
    receiver = '719584032@qq.com'
    # 发送给多人
    # receiver = ['123@qq.com','23432@qq.com','719584032@qq.com']

    # 定义标题和内容
    biaoti = "YT API 自动化测试报告"

    # HTML邮件正文
    msg = MIMEText(mail_content, 'html', 'utf-8')
    msg['subject'] = Header(biaoti, 'utf-8')
    msg['from'] = sender
    msg['to'] = receiver
    # 发送给多人,已逗号为分隔符,针对receiver这个变量
    # msg['to'] =','.join(receiver)

    # SSL协议端口号要使用465
    smtp = smtplib.SMTP_SSL(smtpserver, 465)

    # HELO 像服务器标识用户身份
    smtp.helo(smtpserver)

    # 服务器返回结果确认
    smtp.ehlo(smtpserver)

    # 登陆用户
    smtp.login(user, password)
    print("开始发送邮件.............")
    smtp.sendmail(sender, receiver, msg.as_string())
    smtp.quit()
    print("邮件发送完成.....................")


    if __name__ == '__main__':
    path = 'E:\testreport\YTtest.html'
    send_email(path)
  • 相关阅读:
    animate动画回调函数
    triggerHandler不执行事件默认值
    trigger自动执行事件
    js与jquery对象的互转
    让低版本浏览器支持html5的标签
    闭包的好处罗列
    AJAX跨域
    php能干什么?
    concat() 方法用于连接两个或多个数组。
    使用 v-cloak 防止页面加载时出现 vuejs 的变量名
  • 原文地址:https://www.cnblogs.com/5566yesongqiao/p/12030860.html
Copyright © 2020-2023  润新知