通过 EWS 使用 python 代码访问 Outlook 办公室邮箱(收件箱中的邮件)

Access Outlook office mailbox(mails in inbox) using python code through EWS

我正在使用 python exchangelib 模块

通过 EWS 阅读 Outlook 邮件

我用于身份验证的凭据:电子邮件和应用程序密码

由于一些安全原因,平台团队禁用了 App 密码功能,我最终访问了邮箱,因为我不确定如何在没有 App 密码的情况下访问邮箱???

如果有任何替代应用程序密码的方法,请建议我..

注意:我的 python 脚本是 运行 在 Linux VM

当您使用电子邮件和应用程序密码时,这是在使用基本身份验证,这就是您的平台团队禁用它的原因。您需要转而使用 oAuth https://ecederstrand.github.io/exchangelib/#oauth-authentication and make use of the client_credentials flow https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-client-creds-grant-flow. So you then use a client secret or certificate rather then username & pword. When using this flow you need to make sure you impersonate the Mailbox your trying to access and also don't use Autodiscover because that will fail with that flow. By default this will give you access to all mailboxes in a tenant so if this is a problem you can scope it down to just the mailboxes you need to access https://techcommunity.microsoft.com/t5/exchange-team-blog/application-access-policy-support-in-ews/ba-p/2110361