httprunner/HttpRunnerManager

定时报告不支持outlook邮箱

xumeng20102722 opened this issue · 1 comments

smtplib.SMTPAuthenticationError: (535, b'Error: \xc7\xeb\xca\xb9\xd3\xc3\xca\xda\xc8\xa8\xc2\xeb\xb5\xc7\xc2\xbc\xa1\xa3\xcf\xea\xc7\xe9\xc7\xeb\xbf\xb4: http://service.mail.qq.com/cgi-bin/help?subtype=1&&id=28&&no=1001256')
定时报告是否支持outlook邮箱?

邮箱协议主要是stmp、pop和微软的exchange,你先搞清楚你邮箱的协议是什么;我们公司用的是exchange,所以得稍微改一下代码才能发exchange的邮件。
具体需要修改的大概代码如下:
HttpRunnerManager-master\HttpRunnerManager-master\ApiManager\utils\emails.py

from exchangelib import *

输入你的域账号如example\leo

    cred = Credentials(EMAIL_SEND_DOMAINUSERNAME, EMAIL_SEND_PASSWORD)
    to_recipients=receiver.split(',')
    config = Configuration(server=smtp_server, credentials=cred, auth_type=NTLM)
    a = Account(
        primary_smtp_address=EMAIL_SEND_USERNAME, config=config, autodiscover=False, access_type=DELEGATE
    )

    # 此处为用来发送html格式邮件的文件路径

    with io.open(html_report_path, 'r', encoding='utf-8') as stream:
        send_file = stream.read()


    body = HTMLBody("附件为定时任务生成的接口测试报告,请查收,谢谢!")
    m = Message(
        account=a,
        folder=a.sent,
        subject=u'接口测试报告',
        body=body,
        to_recipients=to_recipients,
    )
    myfile = FileAttachment(name='TestReports.html', content=open(html_report_path, 'rb').read())
    m.attach(myfile)
    m.send_and_save()