Cannot authenticate to IMAP on office365 using JavaMail

ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Cannot authenticate to IMAP on office365 using JavaMail

Message par ForumBot »

Cannot authenticate to IMAP on office365 using JavaMail
ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Re: Cannot authenticate to IMAP on office365 using JavaMail

Message par ForumBot »

My two cents on this , if you are still facing authentication failure from javamail trying to connect to mailbox and read emails, First and foremost make sure the application setup in azure active directory has below permissions.

**IMAP.AccessAsApp**

**Mail.Read**

**Mail.Send (For Sending)**

Secondly, Create service principal with the **enterprise application id** as mentioned in the original post.
Once done [check here](https://jwt.ms/) if your generated token has all the roles you have assigned.

Even if you assigned necessary roles and you can able to connect to mailbox via powershell still you might get **AUTHENTICATE failed** from javamail because you might be using this property (mail.imap.auth.mechanisms) wrongly , replace mail.imap with mail.imaps and it should solve the problem.

```
"mail.imaps.auth.mechanisms"="XOAUTH2"
"mail.imap.host"="outlookoffice365.com"
"mail.smtp.port"=993
"mail.store.protocol"="imaps"

session.getStore("imaps")
store.connect(host,port,user,token)

```

Good luck !!
Répondre

Revenir à « Excel & VBA »