Troubleshoot Office 365 IMAP Connection Timeouts in JavaMail
Question details
Investigate why a JavaMail application intermittently times out when connecting to Office 365 IMAP after earlier successful connections.

- Product
- Microsoft 365 Exchange Online IMAP and JavaMail
- Device & OS
- not provided
- Scenario
- A Java application connects to Office 365 mail using IMAP or POP3 and later attempts another connection.
- Observed behavior
- A later connection to outlook.office365.com on port 993 times out, and the application reports closed-folder errors.
Identify whether the failing connection uses IMAP or POP3, and record the time, endpoint, exception stack trace, and JavaMail configuration. Remove passwords, access tokens, and message content from any logs you share.
Review JavaMail connection handling and timeout settings
Use application diagnostics to determine whether connection reuse, network delays, or excessive connection attempts contribute to the timeout.
Check the JavaMail session properties: IMAP over SSL uses outlook.office365.com on port 993. If the application uses POP3 instead, check its separate POP3 settings and port 995.
Review the code that opens and closes each Store and Folder. Close resources when finished and check that the application does not attempt to use a folder after its connection has closed.
In the JavaMail properties used by the application, review mail.imaps.connectiontimeout and mail.imaps.timeout for IMAP over SSL. Set appropriate values in milliseconds so connection and read delays can be distinguished.
Enable JavaMail session debugging with Session.setDebug(true), reproduce the issue, and compare timestamps with the exception stack trace. Sanitize the output before sharing it.
Review application logs for repeated connections or concurrent sessions around the failure. Reduce unnecessary connection creation and investigate possible Exchange Online throttling or service limits rather than assuming a specific rate limit.

Check Exchange Online access and seek targeted support
Use this approach to separate mailbox or service issues from problems in the custom Java application.
Use WPS Office as an Alternative for Office Documents
WPS Office is a free, lightweight alternative for working with Office documents. Its familiar interface and Microsoft Office format compatibility make it easy to move everyday document work, though it does not fix JavaMail or Exchange Online connections.

Frequently Asked Questions
What server and port should JavaMail use for Office 365 IMAP?
For IMAP over SSL, configure outlook.office365.com on port 993. Check that the JavaMail properties match the protocol your application actually uses.
Can I view the outlook.office365.com IMAP server logs?
Customers generally cannot directly browse those server-side logs. Collect sanitized JavaMail debug output and timestamps, then contact Microsoft 365 support if you suspect an Exchange Online service issue.
Does a timeout mean my application has hit an IMAP rate limit?
Not necessarily. A timeout can also involve network connectivity, connection handling, or service conditions. Review connection frequency and concurrent sessions, and check for evidence of throttling before drawing a conclusion.
Why does JavaMail report a closed folder after a timeout?
The folder may no longer be usable because its underlying connection was closed or lost. Inspect the earliest exception and the code that opens and closes the Store and Folder.
Where should I ask for help with my JavaMail code?
Use a Java support forum for application code and connection handling. Include a minimal example and sanitized debug logs; contact Microsoft 365 support separately for suspected mailbox or Exchange Online service issues.




