Large Mail Folder and imapsync Error “NO Server Unavailable. 15”

I was having issues migration the “Sent Items” folder on a hosted Exchange 2013 account to Microsoft 365. The hosted Exchange 2013 server was returning a “NO Server Unavailable. 15” error when trying to select the “Sent Items” folder with 33,000 messages.

Digging further, I couldn’t find anything until I stumbled upon this thread on the Microsoft forums.

I’ve come across this issue twice with 2 different exchange 2013 farms while setting up IMAP to use IMAPSync to migrate mail. The issue only happened when accessing 1 folder with lots of mail messages. A simple test is to use OpenSSL to verify the issue like:

openssl s_client -quiet -crlf -connect
A01 login domain/user password
A02 LIST “” *
A03 SELECT “problem folder”

IMAP will return: A03 NO Server Unavailable. 15

After change lots of IMAP settings, the resolution is to enable IMAP protocol logging. It was previously (by default) disabled and this issue would happen. We disabled it again and the problem returned for the same mailbox. Re-enabled logging en voila works.

Set-ImapSettings -Server <server-name> -ProtocolLogEnabled $true

Hope this helps someone!