御命丹心

萧瑟悲声秋风起,刹忆寒蝉未鸣时

导航

邮箱处理

#excel报告
def Email_excel(data):
    try:
        fromaddr = '1836166651@qq.com'
        password = 'rbekwgamdokabgjh'
        toaddrs = ['1836166651@qq.com']
        #toaddrs = value1

        content = '最新自动化用例执行结果已写入请查看附件与log日志'
        textApart = MIMEText(content)

        excelFile = '../testData/alltestcase.xlsx'
        excelApart = MIMEApplication(open(excelFile,'rb').read())
        excelApart.add_header('Content-Disposition', 'attachment', filename=excelFile)

        txtFile = '../log/%s.txt'%data
        txtApart = MIMEApplication(open(txtFile, 'rb').read())
        txtApart.add_header('Content-Disposition', 'attachment', filename=txtFile)

        m = MIMEMultipart('related')
        m.attach(textApart)
        m.attach(excelApart)
        m.attach(txtApart)

        m['Subject'] = '自动发送测试报告'
        m['From'] = '王大锤'
        m['to'] = '每日监控'

        server = smtplib.SMTP('smtp.qq.com')
        server.login(fromaddr, password)
        server.sendmail(fromaddr, toaddrs, m.as_string())
        print('自动化测试报告自动发送成功')
        #log.logger.info('自动化测试报告自动发送成功')
        server.quit()
    except smtplib.SMTPException as e:
        print('error:', e)  # 打印错误
        log.logger.info(e)

 

posted on 2020-07-10 19:33  正法  阅读(138)  评论(0编辑  收藏  举报