Sending Emails Using OAuth Authentication with Azure AD and Exchange Online

Akash Sharma 0 Reputation points
2025-01-14T06:20:46.98+00:00

Hello Everyone,

Since Microsoft has disabled Basic Authentication in Exchange Online for sending emails, I am trying to implement OAuth 2.0 with the Exchange Online service.

To set this up, I have taken the following steps:

  1. Created a new app in Azure AD.
  2. Granted all the necessary permissions for sending emails.
  3. Added the required Office 365 Exchange Online permissions.

I am successfully able to generate an access token using the App's Client ID and Client Secret from my PHP application. However, when I attempt to send emails, I consistently encounter the following error message:

2025-01-14 05:48:07 SMTP INBOUND: "535 5.7.3 Authentication unsuccessful
[BMXPR01CA0079.INDPRD01.PROD.OUTLOOK.COM 2025-01-14T05:48:07.485Z 08DD3328E3002B68]" 2025-01-14 05:48:07 SERVER -> CLIENT: 535 5.7.3 Authentication unsuccessful [BMXPR01CA0079.INDPRD01.PROD.OUTLOOK.COM 2025-01-14T05:48:07.485Z 08DD3328E3002B68] 2025-01-14 05:48:07 SMTP ERROR: AUTH command failed: 535 5.7.3 Authentication unsuccessful [BMXPR01CA0079.INDPRD01.PROD.OUTLOOK.COM 2025-01-14T05:48:07.485Z 08DD3328E3002B68] SMTP Error: Could not authenticate.

Can you please help me to resolve this quickly ?

Thanks

Windows for business Windows Client for IT Pros Directory services Active Directory
Microsoft 365 and Office Install, redeem, activate For business Windows
Microsoft Security Microsoft Graph
{count} votes

1 answer

Sort by: Most helpful
  1. Ammar haider Rizvi 0 Reputation points
    2025-01-14T10:18:00.65+00:00

    What authentication method have you configured, as shown in the screenshot below? While this is optional for the user, it can simplify the authentication process and enhance convenience. User's image

    Also can you please share how your are authenticating the User.

    The Above Redirect URL is used to Authenticate the URL of the platform from where you will be sending the email or accessing the Tokens. After configuring the Above URL you will receive the Pop-Up regarding consent to use the Authentication App. You can refer to the below image.

    User's image

    Once you have the consent then you will be able to send the email.

    Hope this will help!

    Also if you are satisfied with the Above content please mark it as "Answer**"**.


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.