Office365 SMTP AUTH XOAUTH2 Fails with “535 5.7.3 Authentication unsuccessful”

If you successfully minted an OAuth2 access token for your Azure Entra Id App, but then it fails when attempting to use it in the SMTP protocol for sending email with the error: AUTH XOAUTH2 user=xxx auth=Bearer ********************** 535 5.7.3 Authentication unsuccessful [BN9PXXXA0336.namprd03.prod.outlook.com 2024-04-16T12:11:26.548Z 08DC9999186DF999] Check your Entra Id App Registration to make sure you have the following App Permissions:

How to Troubleshoot Office365 IMAP AUTHENTICATE XOAUTH2 Failed

Question: We have an issue reading mail and we see the below error message in log Login: DllDate: Oct 27 2023 ChilkatVersion: 9.5.0.96 UnlockPrefix: *** UnlockStatus: 2 Architecture: Little Endian; 32-bit Language: *** VerboseLogging: 0 imapServer: outlook.office365.com loginX(2219ms): login: abc@example.com greeting: * OK The Microsoft Exchange IMAP4 service is ready. [***] authenticateXOAuth2(2219ms): xoauth2Imap(2219ms): ConnectionType: SSL/TLS ImapCmdSent: aaab AUTHENTICATE XOAUTH2 ImapCmdResp: […]

Office365 App Setup for SMTP, POP, IMAP OAuth2 Client Credentials

This blog post walks you through the complete Azure App Registration process, including the subsequent Exchange Online PowerShell commands needed to achieve the OAuth2 client credentials flow for Office365 email sending and reading via the SMTP, IMAP, and POP3 protocols. I wish there was an “easy button”, but unfortunately it does not exist. Step 1. Register an Azure App Go […]

office365.com SMTP, POP3, IMAP OAuth2 Tips, Hints, and Solutions

This page will be updated as time progresses with what we’ve learned about getting things working with OAuth2 authentication for office365.com using the email protocols: SMTP, POP3, and IMAP. How do Other Office365 Users Send Email using my App Registered in my Azure Active Directory? It’s important to understand Tenancy in Azure Active Directory Apps.   See this https://learn.microsoft.com/en-us/azure/active-directory/develop/single-and-multi-tenant-apps When you […]

Office365 Modern Authentication for IMAP, POP3, and SMTP

This post documents how to implement Modern Authentication (OAuth2) for Office365 for the IMAP, POP3, and SMTP protocols.  The very first thing you’ll need to do is to create an “App Registration” in Azure Active Directory. See this Chilkat blog post for Instructions for Setting Up an App Registration in Azure for Modern Authentication for IMAP, SMTP, and POP3. It’s […]

Create Azure App Registration for use with IMAP, POP3, and SMTP

1) Go to https://portal.azure.com/#home and login to your Microsoft account. then go to Azure Active Directory.   2) Click On App Registrations * Copy your Tenant ID, you’ll need it later. 3) Click on “+ New registration” 4) Name your App and Click Register. Give it a name. For the Redirect URI, select “Web” and then use “http://localhost:3017/”. Your application […]

smtp.office365.com – Failed to get initial SMTP Response

If something on the client-side is blocking communications, such as a hardware or software firewall, or anti-virus, then it may be that a TLS connection is established, but then trying to read the 1st message from the server gets blocked.  When this happens, the contents of the LastErrorText look like this.   (The LastErrorText for a successful connection is shown below.) […]

SMTP / Office 365 / OAuth2 : SmtpCmdResp: 535 5.7.3 Authentication unsuccessful

Question: A customer wants to send emails with Office 365 and OAuth2 Authentication. The setup of the application in Azure is OK. It works for one user. For another user we have the following error: SmtpCmdResp: 535 5.7.3 Authentication unsuccessful [****.****.prod.outlook.com] For authentication I use the example: https://www.example-code.com/powerbuilder/office365_oauth2_access_token.asp What is surprising is that for the second user on same PC, […]

Office365 SMTP Error: 554 5.2.0 STOREDRV.Submission.Exception:SendAsDeniedException.MapiExceptionSendAsDenied;

Question: I’m trying to send email using SMTP via smtp.office365.com, and I get this error: 554 5.2.0 STOREDRV.Submission.Exception:SendAsDeniedException.MapiExceptionSendAsDenied; Failed to process message due to a permanent exception with message Cannot submit message. 0.35250:0A001485, 1.36674:0A000000, 1.61250:00000000, 1.45378:02000000, 1.44866:59020000, 1.36674:0E000000, 1.61250:00000000, 1.45378:5E020000, 1.44866:F8000000, 16.55847:BC030000, 17.43559:0000000024020000000000000000000000000000, 20.52176:140FFA8B1500001000000000, 20.50032:140FFA8B8517001000000000, 0.35180:F1030000, 255.23226:09000000, 255.27962:0A000000, 255.27962:0E000000, 255.31418:F1030000, 0.35250:0300C981, 1.36674:0A000000, 1.61250:00000000, 1.45378:02000000, 1.44866:3A000000, 1.36674:32000000, 1.61250:00000000, 1.45378:3F000000, 1.44866:01000000, 16.55847:A6000000, […]

Authentication Problem with Sending Email in Office365 using SMTP

If SMTP authentication (using login/password) fails for your smtp.office365.com account, then it may be that your account is configured to require MFA (multi-factor authentication).   You may need to change settings to allow for legacy authentication (single-factor auth).   See https://docs.microsoft.com/en-us/azure/active-directory/conditional-access/block-legacy-authentication Also, an app password may be required.  See https://docs.microsoft.com/en-us/azure/active-directory/user-help/multi-factor-authentication-end-user-app-passwords