This issue has been flagged in the tracker, but I’m not sure that anyone has sponsored or initiated work on it. ERPNext already supports OAuth in other contexts, but from quick glance at the microsoft docs it’s not quite as simple as just grabbing a token and sending it in place of a password.
I’m surprised I didn’t notice this before, but the email account doctype has supported OAuth for gmail since July. I don’t know the first thing about the M365 implementation, but unless there are some major deviations I’d think that porting it over might be relatively straightforward.
The email/oauth.py has class OAuth it needs to use refresh_token and access_token from “Connected App”/“Token Cache” instead of current custom logic. Class implementation won’t change much, instantiation will need to change to use correct params.
EmailAccount.access_token and EmailAccount.refresh_token will be removed and EmailAccount.connected_app link field needs to be added.
authorize() button is already part of ConnectedApp
This will make it generic. Google, Microsoft any other using XOAUTH will be able to use this without any code changes. I’m tweaking things locally and trying out if it works.
There are a lot of threads talking about this
Since some people are working on it, maybe our testing info is useful on PR comments …
Anyway, we can’t get IMAP or POP mail working yet … probably some missconfiguration about scopes, API permissions on tenant, or something like that. I see that your case is different and it is working now. I keep trying!
I followed all the steps above and saw that I successfully signed in to https://mysignins.microsoft.com/. But I could not sync the emails to the inbox. Is there any other setting I need to do?
Request your support in detailed steps on configuring Office365 email with OAuth. I have tried several times with above steps but email always fails with error “please check your login credentials “.