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

Granville Rex 6 Reputation points
2020-03-25T20:28:22.57+00:00

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 @harsh.com .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 permissions for the Graph API (Mail.ReadWrite, Mail.Send) as well as the Exchange API (full_access_as_app). In my app, I'm able to request and receive valid tokens from the endpoints for both APIs.

When I pass either 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

This error comes after what appears to be a successful login to the SMTP server:

<smtpAuthenticate>  
<smtp_host>smtp.office365.com</smtp_host>  
<smtp_port>587</smtp_port>  
<smtp_user>[test]@outlook.com</smtp_user>  
<auth-method>XOAUTH2</auth-method>  
<smtpAuthMethod>XOAUTH2</smtpAuthMethod>  
<smtpAuthenticate>  
<login_method>NONE or already authenticated</login_method>  
</smtpAuthenticate>  
<ConnectionType>SSL/TLS</ConnectionType>  
</smtpAuthenticate>  

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?

Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
21,449 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Marta Lisa DeBerard 1 Reputation point
    2020-08-22T23:57:40.287+00:00

    Did you ever figure out an answer for this? My company is experiencing the same error message when trying to set up STMP messages. I thought it might have something to do with the two step authentication process.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.