Microsoft 365 Error Codes

Fix Microsoft 365 Email Sending Error 401 Unauthorized in .NET

Khadija KhanKhadija Khan Oct 28, 2026 870 views

Question details

A .NET application encounters a 401 Unauthorized error when attempting to send emails through Microsoft 365.

How to Fix Microsoft 365 Email Sending Error 401 Unauthorized in .NET
Product
Microsoft 365
Device & OS
not provided
Scenario
Sending emails programmatically from a .NET or C# application using Microsoft 365 credentials.
Observed behavior
The application throws a 401 Unauthorized error during mail submission because basic authentication has been deprecated in favor of Modern Authentication.
Before you start

Ensure you have administrative access to your Microsoft Entra ID (formerly Azure AD) tenant to register your .NET application and configure the required API permissions.

Solution 1Recommended

Migrate to OAuth 2.0 Modern Authentication

Replace the deprecated basic authentication in your .NET application with OAuth 2.0 using the Microsoft identity platform.

Microsoft 365 has permanently disabled basic authentication for Exchange Online to improve security. Applications using standard SMTP with a username and password will fail with a 401 Unauthorized error.

To restore email functionality, you must transition to Modern Authentication (OAuth 2.0) by implementing the Microsoft Authentication Library (MSAL) and using Microsoft Graph API or OAuth-based SMTP submission.

1
Register your application in Microsoft Entra ID

Log in to the Microsoft Entra admin center, navigate to App registrations, and create a new registration for your .NET application.

2
Configure API permissions

Go to the API permissions section of your registered app, click 'Add a permission', select Microsoft Graph, and add the 'Mail.Send' permission (either Delegated or Application depending on your architecture).

3
Generate a Client Secret

Navigate to 'Certificates & secrets', create a new client secret, and securely store the value in your application's configuration file.

4
Implement MSAL in your .NET code

Install the Microsoft.Identity.Client NuGet package and update your codebase to acquire access tokens using your Tenant ID, Client ID, and Client Secret.

5
Update the mail sending logic

Replace your basic SMTP client code with HTTP POST requests to the Microsoft Graph API endpoint (https://graph.microsoft.com/v1.0/users/{user-id}/sendMail) passing the acquired OAuth token in the Authorization header.

Migrate to OAuth 2.0 Modern Authentication
Developer Support Resources: Because this involves custom .NET development, you can find specific code implementation guidance and troubleshoot authentication flows in the Microsoft Q&A forums dedicated to Microsoft Identity.
Free Microsoft Office alternative

Looking for a Lightweight Alternative to Microsoft Office?

While resolving backend development and authentication errors in Microsoft 365, you might also be looking for a streamlined, hassle-free office suite for your daily document needs. WPS Office offers a free, lightweight, and highly compatible alternative to Microsoft Office.

  1. 1. Download WPS Office: Visit the official WPS website and click the free download button to get the installer.
  2. 2. Install the Software: Run the setup file and follow the simple on-screen instructions to install the suite on your computer.
  3. 3. Open Your Documents: Launch WPS Office and instantly open your existing .docx, .xlsx, or .pptx files with perfect formatting retention.
Fully compatible with Microsoft Word, Excel, and PowerPoint formats.Lightweight application that uses minimal system resources and installs quickly.Free to use with a familiar, intuitive user interface that requires no learning curve.Built-in PDF editing tools for seamless document management.
microsoft office alternative - wps office

Frequently Asked Questions

Why did basic authentication suddenly stop working in Microsoft 365?

Microsoft systematically deprecated and disabled basic authentication for Exchange Online to protect users from credential-based attacks. All client applications and scripts are now required to use Modern Authentication (OAuth 2.0).

Can I temporarily re-enable basic authentication to fix the 401 error?

No, Microsoft has permanently turned off basic authentication for Exchange Online protocols. Re-enabling it is no longer supported, meaning applications must be updated to use OAuth 2.0.

Where can I find .NET code examples for Microsoft Graph API?

Official code samples, SDK documentation, and developer support for implementing Microsoft Graph in .NET can be found on the Microsoft Learn platform and the Microsoft Q&A developer forums.