smtplib.smtpauthenticationalror:(535,' 5.7.3身份验证失败')for Office365.com

发布于 2025-02-03 08:57:33 字数 1229 浏览 3 评论 0原文

我正在尝试使用以下代码通过Python脚本发送邮件,

import smtplib


def print_hi(name):
    sender = '[email protected]'
    receivers = ['[email protected]']

    message = """some msg"""

    server = smtplib.SMTP('smtp.office365.com', 587)
    server.set_debuglevel(1)
    server.starttls()
    server.ehlo()
    server.login("username", "password")
    server.sendmail(sender, receivers, message)
    server.quit()


if __name__ == '__main__':
    print_hi('PyCharm')

我收到以下错误:

  raise SMTPAuthenticationError(code, resp)
smtplib.SMTPAuthenticationError: (535, b'5.7.139 Authentication unsuccessful, the request did not meet the criteria to be authenticated successfully. Contact your administrator. [BM1PR01CA0144.INDPRD01.PROD.OUTLOOK.COM]')

我研究了许多Stackoverflow问题和Microsoft Blogs,并获得了以下步骤,以启用SMTP为我们的组织启用SMTP:

  1. Enable SMTP auth(启用此功能)
  2. 检查安全默认值(我们无法禁用它,因为它禁用所有MFA,并且在组织级别上都无法遵守)

,因此,如果有人知道如何使其正常工作,请牢记所有安全性,将会有所帮助!

I am trying to send mail via python script using the following code

import smtplib


def print_hi(name):
    sender = '[email protected]'
    receivers = ['[email protected]']

    message = """some msg"""

    server = smtplib.SMTP('smtp.office365.com', 587)
    server.set_debuglevel(1)
    server.starttls()
    server.ehlo()
    server.login("username", "password")
    server.sendmail(sender, receivers, message)
    server.quit()


if __name__ == '__main__':
    print_hi('PyCharm')

I am getting the following error:

  raise SMTPAuthenticationError(code, resp)
smtplib.SMTPAuthenticationError: (535, b'5.7.139 Authentication unsuccessful, the request did not meet the criteria to be authenticated successfully. Contact your administrator. [BM1PR01CA0144.INDPRD01.PROD.OUTLOOK.COM]')

I looked into many StackOverflow questions and Microsoft blogs and got the following steps to enable SMTP for our organization:

  1. Enable SMTP Auth (this is enabled)
  2. Check security defaults (we cannot disable it as it disables all MFA and this won't comply at the organization level)

So if anyone knows how to make it work keeping in mind all the security it would be helpful!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文