535: 5.7.3 Authentication unsuccessful: when using Oauth2 method and SMTP.Send scope

Alex Zonis 70 Reputation points
2023-02-15T19:01:24.29+00:00

I am updating the application to support Oauth2 for obtaining (via IMAP) and sending (via SMTP) emails.

Two weeks ago, both IMAP and SMTP were working. But since February 3rd, the application is not able to send emails; it gives me this error:

535 5.7.3 Authentication unsuccessful [SA0PR11CA0169.namprd11.prod.outlook.com 2023-02-15T18:35:20.708Z 08DB0E6A440E41F8]

It worked before. IMAP still works and able to receive new emails.

Configurations to get the access token:

'clientId' => [client_id],
'clientSecret' => [client_secret],
'urlAuthorize' => "https://login.microsoftonline.com/common/oauth2/v2.0/authorize",
'urlAccessToken' => "https://login.microsoftonline.com/common/oauth2/v2.0/token",	
'scopes' => "openid profile email offline_access https://outlook.office.com/IMAP.AccessAsUser.All https://outlook.office.com/SMTP.Send"

Applications' permissions:
Screen Shot 2023-02-15 at 12.59.23 PM

I use https://swiftmailer.symfony.com/ library to send emails using SMTP. Conversation with the Microsoft server before trying to authenticate using Oauth2 method

 ++ Starting Swift_SmtpTransport
    << 220 SA0PR11CA0169.outlook.office365.com Microsoft ESMTP MAIL Service ready at Wed, 15 Feb 2023 18:35:12 +0000
    
    >> EHLO localhost
    
    << 250-SA0PR11CA0169.outlook.office365.com Hello [2603:8080:2501:df2:487d:8382:4f8b:47c5]
    250-SIZE 157286400
    250-PIPELINING
    250-DSN
    250-ENHANCEDSTATUSCODES
    250-STARTTLS
    250-8BITMIME
    250-BINARYMIME
    250-CHUNKING
    250 SMTPUTF8
    
    >> STARTTLS
    
    << 220 2.0.0 SMTP server ready
    
    >> EHLO localhost
    
    << 250-SA0PR11CA0169.outlook.office365.com Hello [2603:8080:2501:df2:487d:8382:4f8b:47c5]
    250-SIZE 157286400
    250-PIPELINING
    250-DSN
    250-ENHANCEDSTATUSCODES
    250-AUTH LOGIN XOAUTH2
    250-8BITMIME
    250-BINARYMIME
    250-CHUNKING
    250 SMTPUTF8
    
    >> AUTH XOAUTH2 

Other notes:
I have seen similar questions posted by other users. Still, the reply from the Microsoft representative wasn't solving the issue for common tenants and didn't help me to resolve the issue that I have. Links to similar questions:

  1. https://learn.microsoft.com/en-us/answers/questions/1168272/oauth2-for-smtp-send-granting-accesstoken-but-retu
  2. https://learn.microsoft.com/en-us/answers/questions/1168242/smtp-send-oauth-permission-not-working-for-consume
Exchange Online
Exchange Online
A Microsoft email and calendaring hosted service.
6,171 questions
Outlook Windows Classic Outlook for Windows For business
Microsoft 365 and Office Development Microsoft 365 Publishing
Microsoft Security Microsoft Graph
0 comments No comments
{count} votes

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.