SMTP OAuth 2.0 - Client was not authenticated to send anonymous mail during MAIL FROM

  • Thread starter Thread starter gsi_rex
  • Start date Start date
G

gsi_rex

Guest
I am testing OAuth 2.0 integration for SMTP and POP3 in a desktop application. The app has a service component that sends and receives emails from a single account in the background.

I set up a @outlook.com online account to test with. I started a trial of Azure and Office 365 using this account.

I registered my application in Azure and gave it "Mail.ReadWrite" and "Mail.Send" permissions for the Graph API.

In my application, I send an HTTP request to the token endpoint for my Azure tenant and receive a token in response. If I decode the token, I can see that it includes "Mail.ReadWrite" and "Mail.Send" in the "roles" list.

When I pass the token to the mail component and try to send a test email, I get the following error:

530 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM

I'm using the smtp.office365.com server to send over port 587 and it is TLS encrypted. This works fine when I use Basic Auth instead of OAuth. But as soon as I use "XOAUTH2" for the authentication method and pass the auth token, the test send fails.

When I research the error online, I get a lot of hits suggesting using the MX endpoint for the smtp server. I'm unfamiliar with MX endpoints, and it seems like this involves registering a domain on Azure, which I don't think is necessary in this case. Or am I wrong about that?

Does anyone know what could be the cause of this error in my case, or how to troubleshoot this further?

Continue reading...
 
Back
Top