[英]How to connect to Microsoft Exchange Smtp?
Usually, for Gmail and outlook we have app passwords to connect to SMTP (though we can use email passwords by enabling less secure app access).通常,对于 Gmail 和 Outlook,我们有应用程序密码来连接到 SMTP(尽管我们可以通过启用安全性较低的应用程序访问来使用电子邮件密码)。
But for my Microsoft Exchange mail I can't find the app password, nor I can connect my app with the mail to send emails.但是对于我的 Microsoft Exchange 邮件,我找不到应用程序密码,也无法将我的应用程序与邮件连接起来以发送电子邮件。
import smtplib
password = "mypassword"
email = "usrname@tsac-uae.com"
s = smtplib.SMTP('smtp.office365.com', 587)
s.starttls()
s.login(email, password)
I get an error saying我收到一条错误消息
smtplib.SMTPAuthenticationError: (535, b'5.7.139 Authentication unsuccessful,
SmtpClientAuthentication is disabled for the Tenant.
Visit https://aka.ms/smtp_auth_disabled for more information.
[AM9P192CA0015.EURP192.PROD.OUTLOOK.COM]')
To avoid these complications, I need to use an app password.为了避免这些并发症,我需要使用应用密码。 But I can't find how to set up app password in exchange.但我找不到如何设置应用程序密码作为交换。 Also, the steps said in the website is outdated.另外,网站上说的步骤已经过时了。 I can't find enable SMTP anywhere.我在任何地方都找不到启用 SMTP。
You need to enable SMTP submission (an organization-wide setting) within your Microsoft Tenant as per the link you get in the error message, which expands to https://docs.microsoft.com/en-us/exchange/clients-and-mobile-in-exchange-online/authenticated-client-smtp-submission .您需要根据错误消息中获得的链接在 Microsoft 租户中启用SMTP 提交(组织范围的设置),该链接扩展为https://docs.microsoft.com/en-us/exchange/clients-and -mobile-in-exchange-online/authenticated-client-smtp-submission 。
The change can only be performed via powershell.更改只能通过 powershell 执行。 An easy way to perform this change is by logging in at https://shell.azure.com .执行此更改的一种简单方法是登录https://shell.azure.com 。 To use Exchange Online cmdlets in the Azure Cloud Shell, the Exchange Online cmdlets need to be imported using Connect-EXOPSSession
.若要在 Azure Cloud Shell 中使用 Exchange Online cmdlet,需要使用Connect-EXOPSSession
导入 Exchange Online cmdlet。 Once connected, to enable SMTP submission use连接后,启用 SMTP 提交使用
Set-TransportConfig -SmtpClientAuthenticationDisabled $false
Make sure you read the article linked above to understand the security implications.请务必阅读上面链接的文章以了解安全隐患。 Also beware that还要注意的是
If your authentication policy disables basic authentication for SMTP, clients cannot use the SMTP AUTH protocol even if you enable the settings outlined in this article.如果您的身份验证策略禁用了 SMTP 的基本身份验证,则即使您启用本文中概述的设置,客户端也无法使用 SMTP AUTH 协议。 For more information, see Disable Basic authentication in Exchange Online .有关详细信息,请参阅在 Exchange Online 中禁用基本身份验证。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.