带有 oAuth2( token )SMTP 的 Javax 邮件 Office Exchange

标签 java oauth-2.0 smtp office365

有人可以指导我使用 oAuth2 使用 javax 邮件对 office 365 exchange 进行身份验证吗?

transport.connect(mailConfig.getMailUsername(), mailConfig.getMailPassword());

(I Tried also with Bearer + ...

Properties props = new Properties();

            props.put("mail.smtp.port", "587");
            props.put("mail.smtp.host", "smtp.office365.com");
            props.put("mail.smtp.auth.mechanisms", "XOAUTH2");
            props.put("mail.smtp.starttls.enable", "true");
            props.put("mail.debug.auth", "true");
            props.put("mail.debug", "true");
            Session session = Session.getInstance(props);
            session.setDebug(true);
            Transport transport = session.getTransport("smtp");
            transport.connect(mailConfig.getMailUsername(), mailConfig.getMailPassword());

Photo of Permission for Microsoft Azure

Photo of Permission for Microsoft Azure

这是我的堆栈跟踪:

DEBUG SMTP: Attempt to authenticate using mechanisms: XOAUTH2
DEBUG SMTP: Using mechanism XOAUTH2
AUTH XOAUTH2 [...]
535 5.7.3 Authentication unsuccessful [ZR0P278CA0118.CHEP278.PROD.OUTLOOK.COM]

最佳答案

目前不支持使用客户端凭据流进行 SMTP 身份验证。

请参阅 Microsoft 文档中关于 SMTP Protocol Exchange 的注释.

另请参阅 Exchange Team Blog 上的这篇帖子.他们刚刚在 2022 年 6 月添加了对 IMAP 和 POP 的支持。SMTP 还没有,他们还没有分享他们预计何时拥有它的时间表。他们报告说他们将继续支持 SMTP 的基本身份验证(用户名/密码)。

关于带有 oAuth2( token )SMTP 的 Javax 邮件 Office Exchange,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72498780/

相关文章:

java - SonarQube 5.2 无法分析 Java 中的 Multi-catch 表达式

java - 如何删除 Fluent 界面默认方法的未检查警告

java - 如何修复 GridBagLayout 按钮大小

oauth-2.0 - 使用 Graph API 更改 Azure AD B2C 用户密码

c# - 使用外部 SMTP 服务器发送邮件使用未在 Azure Web Apps 的传出 IP 中定义的 IP

node.js - Nodemailer 可以作为独立的 SMTP 服务器吗?

java - 如果不断改变for循环中的条件会发生什么?

javascript - 基于 Angular.js + Node.js/PassportJS 的 SPA 上的 oauth2 身份验证

c# - Azure 上的 Google Analytics API

email - Gmail SMTP 需要 "app password"吗?