【发布时间】:2022-06-29 18:42:10
【问题描述】:
有人可以给我一个指南,通过 oAuth2 使用 javax 邮件对 Office 365 交换进行身份验证吗?
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]
【问题讨论】:
-
密码是你的访问令牌吧?
-
我目前有同样的问题我唯一不同的是使用我从 login.microsoftonline.com/{tenantId}/oauth2/v2.0/token 获得的 access_token(使用 client_credential 授权)而不是密码。结果是完全相同的。我想有一个属性,我们必须将令牌放入其中,因为它不计量我用作密码参数的内容,它总是失败。
标签: java oauth-2.0 smtp office365