How to access to a shared mail box using Oauth2 with Java

Anis S 1 Reputation point
2022-04-27T08:11:26.497+00:00

I'm trying to access a shared mailbox using an Oauth2 and IMAP Protocol, but I have an error saying that the authentification have failed.

Note that I have successfuly connected to my user mailbox (user@harsh.com .com) with a token previously retrieved. But now, I have an issue with trying to connect to my shared mailbox.

Any ideas of how we can access a shared mailbox when it come to an Oauth2 protocol?

In my code Java, I set an object Properties:

Properties props = new Properties();
props.put("mail.imap.ssl.enable", "true");
props.put("mail.imaps.sasl.enable", "true");
props.put("mail.imaps.sasl.mechanisms", "XOAUTH2");
props.put("mail.imap.auth.login.disable", "true");
props.put("mail.imap.auth.plain.disable", "true");
props.put("mail.debug", "false");
props.put("mail.debug.auth", "false");
System.setProperty("mail.mime.multipart.ignoreexistingboundaryparameter", "true");
System.setProperty("mail.mime.multipart.allowempty", "true");
props.setProperty("mail.imaps.auth.ntlm.disable", "true");

and I'm trying to connect after getting my session:

Session session = Session.getInstance(props);
final Store store = session.getStore("imaps");
store.connect(serveur, 993, "user@harsh.com .com/shared_mail_box", accessToken);

But the authentification have failed when I added my (/shared_mail_box) to access my shared mail box, in contrary when I use only my user account (user@harsh.com .com).

Thank you!

Microsoft Authenticator
Microsoft Authenticator
A Microsoft app for iOS and Android devices that enables authentication with two-factor verification, phone sign-in, and code generation.
6,099 questions
Exchange Server Development
Exchange Server Development
Exchange Server: A family of Microsoft client/server messaging and collaboration software.Development: The process of researching, productizing, and refining new or existing technologies.
528 questions
{count} votes