无法从python向Outlook邮件发送状态电子邮件

时间:2019-10-23 22:34:43

标签: python outlook smtp smtp-auth

我正在尝试检查网站的状态并将其发送到Outlook邮件。这就是我所做的-

import requests.exceptions

SITES = ["https://example1.com","https://example2.com"]

for site in SITES:
    try:
        r = requests.get(site)
        r.raise_for_status()  
    except requests.exceptions.ConnectionError as err:
        print("Connection Error in " + site + ":" + "err")
    except requests.exceptions.Timeout as err:
        print("Timeout Error in " + site + ":" + "err")
    except requests.exceptions.HTTPError as err:
        print("HTTP Error in " + site + ":" + "err")
        import smtplib
        from email.mime.multipart import MIMEMultipart
        from email.mime.text import MIMEText

        fromaddr = "example@outlook.com"
        toaddr = "example2@outlook.com"
        msg = MIMEMultipart()
        msg['From'] = fromaddr
        msg['To'] = toaddr
        msg['Subject'] = "Alert: Server Room  "
        body = "HTTP error in  : " + site 
        msg.attach(MIMEText(body, 'plain'))
        server = smtplib.SMTP('smtp.outlook.com', 587)
        server.starttls()
        server.login(fromaddr, "password")
        text = msg.as_string()
        server.sendmail(fromaddr, toaddr, text)
        server.quit()

    else:
        print(site + "is working")

我正在使用Python 3.7.4。我收到此错误-

    raise SMTPAuthenticationError(code, resp)
smtplib.SMTPAuthenticationError: (535, b'5.7.3 Authentication unsuccessful [AM4P190CA0003.EURP190.PROD.OUTLOOK.COM]')

我提供了正确的电子邮件地址和密码。解决方法是什么?

0 个答案:

没有答案