有人可以指导我使用 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/