Fix Outlook Office 365 IMAP Authentication Failure in JavaMail
Question details
Connect a JavaMail application to an Office 365 mailbox using IMAP.

- Product
- Exchange Online IMAP and JavaMail
- Device & OS
- not provided
- Scenario
- A Java application connects to outlook.office365.com to access an Office 365 mailbox.
- Observed behavior
- The server responds to the CAPABILITY command, but authentication with AUTHENTICATE PLAIN fails.
Confirm the mailbox address and check whether the application uses a password or an OAuth 2.0 access token. Have an Exchange administrator available to verify mailbox access and app permissions if needed.
Check the Office 365 IMAP connection settings
Use these settings to rule out an incorrect server, port, or encryption method.
In the JavaMail connection settings, set the IMAP host to outlook.office365.com and the port to 993. Use an implicit TLS connection, such as the imaps protocol.
Set the username in the application's account configuration to the full Office 365 mailbox address and check it for typing errors.
If the application also sends mail, configure smtp.office365.com on port 587 with STARTTLS. This setting does not control IMAP authentication.
Add the account in Outlook through File > Add Account and sign in. A successful sign-in helps determine whether the issue is specific to the Java application.

Use OAuth 2.0 for Exchange Online IMAP
Use OAuth when the application attempts password-based AUTHENTICATE PLAIN against Exchange Online.
Work with Office documents in WPS Office
WPS Office is a free, lightweight alternative for working with documents, spreadsheets, and presentations. Its familiar interface and Microsoft Office format support help you move existing files smoothly. It does not fix Exchange Online IMAP authentication.

Frequently Asked Questions
Why does IMAP CAPABILITY work but authentication fail?
CAPABILITY only shows that the application reached the server and received its capabilities. Authentication can still fail because of the chosen method, token, permissions, or mailbox settings.
Can I use my Office 365 password with AUTHENTICATE PLAIN?
Exchange Online no longer supports Basic authentication for IMAP. Configure your application to use OAuth 2.0 and the XOAUTH2 mechanism instead.
Which port and encryption should I use for Office 365 IMAP?
Connect to outlook.office365.com on port 993 using implicit TLS. Depending on the client, this may be labeled SSL/TLS.
Where can an administrator check whether IMAP is enabled?
In the Microsoft 365 admin center, go to Users > Active users, select the user, and open Mail > Manage email apps to check IMAP access.




