Exchange Connection Problems

Fix JavaMail IMAP XOAUTH2 Authentication Failed on Microsoft 365

Emma BrownEmma Brown Oct 20, 2026 868 views

Question details

Users receive an 'AR1 NO AUTHENTICATE failed' error when attempting to connect to Microsoft 365 via IMAP over SSL using JavaMail and XOAUTH2.

Fix JavaMail IMAP XOAUTH2 Authentication Failed on Microsoft 365
Product
Microsoft 365
Device & OS
not provided
Scenario
A Java application using JavaMail 1.6.2 is trying to authenticate with a Microsoft 365 email account over port 993 utilizing modern OAuth 2.0 (XOAUTH2) but fails during the authentication phase.
Observed behavior
The connection to outlook.office365.com is successfully established, but the Exchange server rejects the authentication token, resulting in the failure message 'AR1 NO AUTHENTICATE failed'.
Before you start

Ensure you have global administrator access to the Microsoft 365 Admin Center and Microsoft Entra ID (formerly Azure AD) to verify application permissions and mailbox settings.

Solution 1Recommended

Verify OAuth Access Token and Microsoft Entra ID Scopes

Ensure your registered application has the correct API permissions and that the token being passed to JavaMail is valid and not expired.

Microsoft 365 requires specific delegated permissions for an application to access IMAP mailboxes via XOAUTH2. If the token lacks these scopes or has expired, Exchange Online will reject the authentication.

1
Access App Registrations

Log into the Microsoft Entra ID portal, navigate to 'App registrations', and select your application.

2
Check API Permissions

Click on 'API permissions' in the left menu. Ensure that the 'IMAP.AccessAsUser.All' delegated permission is added under Office 365 Exchange Online or Microsoft Graph.

3
Grant Admin Consent

If the permission status indicates it needs consent, click 'Grant admin consent for [Your Organization]' to apply the permissions globally.

4
Validate Token Generation

In your Java code, verify that you are requesting a fresh OAuth2 access token immediately before initiating the JavaMail connection, as tokens typically expire after 60 minutes.

Verify OAuth Access Token and Microsoft Entra ID Scopes
Token Decoding: You can use a tool like jwt.ms to decode your generated access token and verify that the required IMAP scopes are present in the 'scp' (scopes) claim.
Free Microsoft Office alternative

Need a Reliable and Lightweight Office Suite? Try WPS Office

While you are busy troubleshooting backend Exchange authentication, you may need a reliable desktop office suite for your daily document tasks. WPS Office is a high-performance, lightweight, and completely free alternative to Microsoft Office.

  1. 1. Download the Installer: Visit the official WPS Office website and click the free download button for your operating system.
  2. 2. Install the Software: Run the lightweight installer to quickly set up WPS Office on your computer.
  3. 3. Open Your Documents: Double-click any Microsoft Word, Excel, or PowerPoint file to open and edit it directly in WPS Office without formatting issues.
100% compatible with Microsoft Office formats like DOCX, XLSX, and PPTXLightweight installation that runs smoothly on almost any deviceFamiliar user interface requiring zero learning curve for Office usersBuilt-in PDF editing and conversion tools
QA img-9

Frequently Asked Questions

What does 'AR1 NO AUTHENTICATE failed' mean in JavaMail?

This error means the connection to the IMAP server was established successfully, but the server rejected the provided credentials or access token. When using XOAUTH2, it typically indicates that the token is expired, invalid, or lacks the necessary API permissions (scopes) in Microsoft Entra ID.

Which API scopes are required for Microsoft 365 IMAP OAuth2?

To authenticate via IMAP using XOAUTH2, your application needs the 'https://outlook.office.com/IMAP.AccessAsUser.All' permission. This must be granted in the Microsoft Entra ID portal under API permissions.

Does JavaMail 1.6.2 support modern authentication (OAuth2)?

Yes, JavaMail versions 1.5.5 and newer, including 1.6.2, natively support the XOAUTH2 authentication mechanism for IMAP, POP3, and SMTP protocols without needing external extensions.

Why is my valid access token still being rejected by Exchange Online?

Even with a valid token, authentication will fail if the target mailbox has IMAP disabled in the Microsoft 365 Admin Center, or if Conditional Access policies (like restricting sign-ins from certain IP addresses) are blocking the connection.