Javax邮局与OAuth2(令牌)SMTP
有人可以给我aguide用oauth2与Javax邮件进行身份验证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());
Microsoft azure的许可照片
fqw54.png“ rel =“ noreferrer”> Microsoft Azure许可的照片
这是我的stackstrace:
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]
Can someone give me aguide to authenticate to office 365 exchange with javax mail with oAuth2?
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
Here is my stackstrace:
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]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
目前不支持使用客户端凭据流进行SMTP身份验证。
请参阅Microsoft的文档中的注释, smtp协议交换。
另外,请参阅交换团队博客。他们只是在2022年6月添加了对IMAP和POP的支持。SMTP还没有那里,他们尚未分享他们期望何时拥有的时间表。他们报告说,他们将继续支持SMTP的基本身份验证(用户名/密码)。
Using the client credentials flow for SMTP Authentication is currently not supported.
See the NOTE in Microsoft's doc on the SMTP Protocol Exchange.
Also, see this post from the Exchange Team Blog. They just added support for IMAP and POP in June 2022. SMTP is not yet there and they have not shared a timeline for when they expect to have it. They report that they will continue to support basic authentication (username/password) for SMTP.
以下是对我有用的属性,假设您在O365帐户上启用了SMTP auth,并且成功地使用范围“ https://outlook.office365.com/smtp.smtp.send offline_access”就代币进行了协商
。 've阅读,在调用transport.connect()时传递您的访问权限,而不是密码,而javamail会处理格式化:
这是由此产生的对话:
好运,希望这可以节省某人的时间!
here are the properties that worked for me, assuming you have SMTP AUTH enabled on your O365 account and have successfully negotiated the token with scope "https://outlook.office365.com/SMTP.Send offline_access"
And then contrary to other advice I've read, pass your accessToken in instead of the password when calling Transport.connect(), and JavaMail will take care of formatting it:
Here's the resulting conversation:
Best of luck, hopefully this will save someone some time!
我认为您需要使用
密码
,然后将null用作我的
I think you need to use
and then use null as a password
For me this was working
截至2022年10月10日,仍然不支持SMTP客户端凭证流。他们宣布了对POP和IMAP的支持,但我没有对SMTP的支持,因此我向Microsoft社区中心提出了一个问题,因为我经历了同一问题。我是由Microsoft团队的一员Greg Taylor告诉我的,SMTP尚不可能进行客户凭证流。他说,他们将宣布何时可用,计划/希望是在年底之前。有关我的问题,请参见此链接,响应 https://techcommunity.microsoft.com/t5/exchange-team-team-blog/announcing-oauth--oauth-2-0-client-client-creient-credentials-flow-flow-support -For-and/ba-p/3562963
As of 10-Nov-2022, the SMTP client credential flow is still not supported. They announced support for POP and IMAP but I saw no support for SMTP so I submitted a question to the Microsoft Community Hub since I am experiencing the same issue. I was told by Greg Taylor, who is part of the EXCHANGE Microsoft team, that client credential flow is not yet possible with SMTP. He said they will announce when it's available, the plan/hope is that it will be by the end of the year. See this link for my question and the response https://techcommunity.microsoft.com/t5/exchange-team-blog/announcing-oauth-2-0-client-credentials-flow-support-for-pop-and/ba-p/3562963