Issues connecting ImapClient to Exchange Office 365

Hello and thanks for any help you can provide.

We’ve had an Coldfusion (Java) application running for over a year now that was making a connection to an exchange outlook account, retrieving messages and saving them to a file server as eml files. It was using the class and using basic authentication. Over the past few days, we have not been able to connect, and it seems the issue is that basic authentication to azure exchange servers have been disabled and you are now required to connect using modern authentication.

I am attempting to update the code to use the following constructor but am failing. Continue to get a connection status of 16.

ImapClient(String host, int port, String username, String authInfo, boolean useOAuth, int securityOptions)

We have setup an application in azure (but to be honest, we’re not sure if we’re even doing it correctly). I’m curious if there is a thorough, guide to accomplish this transition.

Thanks for any help you can provide.


You can use AzureROPCTokenProvider class described in the MS Graph.

Code sample to initialize credentials:

ITokenProvider provider = new AzureROPCTokenProvider(oauth2.Tenant, oauth2.ClientId, "", oauth2.userNameEmail, oauth2.userPassword, 
    new String[] { "" });
NetworkCredential credentials = new OAuthNetworkCredential(oauth2.userNameEmail, provider);

Setting the Azure “Office 365 Exchange Online”/full_access_as_app permission:

  • Application/Manage/API permissions/ + Add a permission

  • Select “APIs my organization uses” tab and search for “Office 365 Exchange Online” as shown in this image : image1.png (24.1 KB)

  • Select “Application permissions” and enable “full_access_as_app” as shown in this image : image2.png (46.7 KB)

MS Documentation link:

Access Mail Services using OAuth

Hope this helps you.


We suggest you please read the following article to achieve your requirement. Hope this helps you.
Using OAuth to access Mail Services