We need to read emails for a batch process using OAUTH2 with IMAP in our Java Code. We followed the instructions from here: https://learn.microsoft.com/en-us/exchange/client-developer/legacy-protocols/how-to-authenticate-an-imap-pop-smtp-application-by-using-oauth.
We are now getting this error : A1 NO AUTHENTICATE failed.
The java code I followed is from here : https://ralph.blog.imixs.com/2022/10/24/how-to-access-outlook-office365-com-imap-form-java-with-oauth2/
Below are the following things I did:
- Registered the application
- Gave the permission "IMAP.AccessAsApp" in API Permissions under "Office 365 Exchange Online (1)"
- Granted admin consent in API Permissions page.
- Generated the client secret
- Used the client secret and Obtained the access token as per the java code in the above link.
- Registered service principals in Exchange by running the following commands in my windows powershell:
Install-Module -Name ExchangeOnlineManagement
Import-module ExchangeOnlineManagement
Install-Module -Name ExchangeOnlineManagement <organization id>
New-ServicePrincipal -AppId <Application id> -ServiceId <serviceid> -Organization <org id>
- Added mailbox permission using the following command in powershell:
Add-MailboxPermission -Identity "useremaild" -User <serviceid> -AccessRights FullAccess
This is what I'm trying to achieve: https://techcommunity.microsoft.com/t5/exchange-team-blog/announcing-oauth-2-0-client-credentials-flow-support-for-pop-and/ba-p/3562963