• 测试报告以附件形式发送


    import smtplib
    from email.mime.multipart import MIMEMultipart
    from email.mime.text import MIMEText
    from email.header import Header
    
    def send_mail(report_name, receiver ='***@qq.com'):
        '''
        发送测试报告到邮箱
        :param report_name: 需要发送的测试报告
        :param receiver: 邮件接收人
        :return:
        '''
        # ----------------------------------------------------------
        # 获取邮件正文,读取测试报告的内容
        f = open(report_name, 'rb')
        mail_body = f.read()
        f.close()
        # 邮件服务器
        smtpserver = 'smtp.163.com'
        # 发件人和密码
        sender = '***@163.com'
        password = '******'
        # 接收人
        receiver = receiver
        # 邮件主题
        subject = u'自动化测试报告'
        # ----------------------------------------------------------
        # 连接登录邮箱
        server = smtplib.SMTP(smtpserver, 25)
        server.login(sender, password)
        # ----------------------------------------------------------
        # 添加附件
        sendfile = open(report_name, 'rb').read()
        att = MIMEText(sendfile, "base64", 'utf-8')
        att['Content-Type'] = 'application/octet-stream'
        att['Content-Disposition'] = 'attachment;filename="report.html"'
        msg = MIMEMultipart('related')
        msgtext = MIMEText(mail_body, 'html', 'utf-8')
        msg.attach(msgtext)
        msg['From'] = sender
        msg['To'] = receiver
        msg['Subject'] = Header(subject, 'utf-8').encode()
        msg.attach(att)
        # ----------------------------------------------------------
        # 发送邮件
        server.sendmail(sender, [receiver], msg.as_string())
        server.quit()
        print("发送成功!")
    
    send_mail("report.html")

    来源:https://www.cnblogs.com/nicole-zhang/p/10394668.html

  • 相关阅读:
    Knime 使用 初探
    MySql可视化工具MySQL Workbench使用教程
    MySQL导入sql 文件的5大步骤
    Import MySQL Dumpfile, SQL Datafile Into My Database
    导入已有的vmdk文件,发现网络无法连通
    VirtualBox镜像复制载入
    对自己说的话
    linux遇见的问题
    vbox下安装 linux 64 bit出现“kernel requires an x86_64 cpu
    Servlet 3 HttpServletRequest HttpServletResponse 验证码图片 form表单
  • 原文地址:https://www.cnblogs.com/pantheryao/p/12170021.html
Copyright © 2020-2023  润新知