IMAP error: User is authenticated but not connected?

Gaurav Baranwal 11 Reputation points
2023-09-11T07:41:29.35+00:00

Hi Team,

I am encountering a problem while performing mail operations such as move message or retrieve message for more than 20 requests. error which i am receiving is: "User is connected but not authenticated.".

followed all instructions mentioned at :

  1. https://learn.microsoft.com/en-us/exchange/client-developer/legacy-protocols/how-to-authenticate-an-imap-pop-smtp-application-by-using-oauth#use-client-credentials-grant-flow-to-authenticate-smtp-imap-and-pop-connections.
  2. https://learn.microsoft.com/en-gb/exchange/clients-and-mobile-in-exchange-online/opt-in-exchange-online-endpoint-for-legacy-tls-using-pop3-or-imap4

I tried with both imap host (outlook.office365.com, imap-legacy.office365.com) but that didn't help.

below IMAP settings used:

please can someone help here, how to use imap with oauth2 using javax mail api.

prop.setProperty("mail.store.protocol", imaps);
prop.put("mail.imap.ssl.enable", "true");
prop.put("mail.imaps.sasl.enable", "true");
prop.put("mail.imaps.sasl.mechanisms", "XOAUTH2");
prop.put("mail.imap.auth.login.disable", "true");
prop.put("mail.imap.auth.plain.disable", "true");
prop.put("mail.imap.host", outlook.office365.com);
prop.put("mail.imap.port", "993");		
Microsoft Exchange Online
Outlook
Outlook
A family of Microsoft email and calendar products.
3,814 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.
544 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.