Exchange Connection Problems

Troubleshoot Office 365 IMAP Connection Timeouts in JavaMail

Khadija KhanKhadija Khan Nov 22, 2026 868 views

Question details

Investigate why a JavaMail application intermittently times out when connecting to Office 365 IMAP after earlier successful connections.

Troubleshoot Office 365 IMAP Connection Timeouts in JavaMail
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.
Before you start

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.

Solution 1Recommended

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.

1
Verify the endpoint

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.

2
Inspect connection lifecycle

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.

3
Set diagnostic timeouts

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.

4
Capture client-side diagnostics

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.

5
Check connection frequency

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.

Review JavaMail connection handling and timeout settings
Closed-folder errors: A closed-folder error can follow a lost or closed connection; use the earliest exception and debug output to investigate the underlying cause.
Free Microsoft Office alternative

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.

Free and lightweight for everyday office workCompatible with Microsoft Office formats, including DOCX, XLSX, and PPTXFamiliar document, spreadsheet, and presentation tools support an easy transitionKeep working with Office files while investigating the separate IMAP connection issue
QA img-9

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.