[Tutorial] Connecting Frappe/ERPNext to Microsoft 365 mail services OAuth

you are trying to authorize api access with an admin user who is not registered the email setup. I got the same error at least when hitting the authorize api access button. solved by using an account connected to the setup to authorize, not admin user.

+20 1111817748
contact me on whatsapp i have the solution

Hey everyone, been having these problems as well. Managed to get a “no-reply” email working with M365, however my problem is that after a while (between 2h and 24h) it seems that the email account “loses” access to the API authorization, and I need to do the “Authorize API Access” loop again, otherwise it does not send out emails from Frappe. Any one has an idea about this?

Hi @PedroJACorreia:

Seems refresh token is not being generated …

Check your connected app doctype.

See this docs too:
https://frappeframework.com/docs/user/en/microsoft-email-oauth#service-principal-authentication

Hope this helps.

Hi avc, thanks for the quick reply.

Is there a way to force the token generation? Mine is being generated, but the problem persists; once I “Authorize API Access” in the email account menu for my no-reply account, it works just fine. But after a certain amount of time (1-2 hours) it seems to lose connection to M365 and asks for the “Authorize API Access” again. Doing it again makes it work again for a short time, then rinse and repeat.

image

I don’t have the “Authenticate as Service Princpal” checkbox as the documentation suggests. Is there something I’m missing?

image

Check your Token Cache. It needs to have refresh_token field populated. To obtain refresh token offline_access scope is required.

Not related to Microsoft, some providers may make it mandatory to “verify app” or set it up “production mode” to start obtaining refresh tokens.

2 Likes