smtplib.smtpauthenticationalror:(535,' 5.7.3身份验证失败')for Office365.com
我正在尝试使用以下代码通过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:
- Enable SMTP auth(启用此功能)
- 检查安全默认值(我们无法禁用它,因为它禁用所有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:
- Enable SMTP Auth (this is enabled)
- 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论