Basic authentication for POP in Exchange Online has been disabled. See Deprecation of Basic authentication in Exchange Online for details. Azure Active Directory is now called Microsoft Entra ID. The app registration steps below are based on the portal interface at the time of writing.
As Exchange Online moves away from basic authentication, OAuth is now supported for POP. Developer information is available on the following page:
Here is a basic C# sample. I won’t explain the code itself, so please read it alongside the developer documentation above. It implements only the minimum functionality, so a full implementation requires knowledge of the Microsoft identity platform and POP. This is a C# console application that uses MSAL for authentication. It uses the device authorization grant flow because there is little benefit in creating a new POP client that uses the authorization code flow. I’ll also show how to register the application in Azure AD for this flow.
There is little benefit in connecting to Exchange Online using POP, so you should consider migrating to Microsoft Graph instead.
The sample was tested with MSAL (Microsoft.Identity.Client) version 4.54.1 on .NET Framework 4.8.
Warning
This is a minimal example; a production implementation needs appropriate error handling and POP response processing. LIST 1 retrieves the size of the first message; it does not download the message itself.
using Microsoft.Identity.Client; using System; using System.IO; using System.Linq; using System.Net.Security; using System.Net.Sockets; using System.Text; using System.Threading.Tasks;
namespacePopClientDemo { classProgram { privateconststring ClientId = "<CLIENT ID OF YOUR APP>"; privateconststring Authority = "https://login.microsoftonline.com/organizations"; privatestaticreadonlystring[] Scopes = newstring[] { "https://outlook.office.com/POP.AccessAsUser.All" };
staticvoidMain(string[] args) { var tokenResult = GetToken().Result; string token = tokenResult.AccessToken; string user = tokenResult.Account.Username; // In case of shared mailbox access, replace the value of user variable with the UserPrincipalName or PrimarySmtpAddress of the shared mailbox. UserPrincipalName is recommended. string XOAUTH2 = Base64Encode($"user={user}\u0001auth=Bearer {token}\u0001\u0001");
using (ExoPopClient client = new ExoPopClient()) { // Receive the greeting. var response = client.Receive();
if (!response.StartsWith("+OK")) { thrownew Exception("Unexpected response received."); }
Go to the Azure portal and sign in to the Azure Active Directory admin center.
Go to the Azure Active Directory blade.
Select Manage > App registrations > New registration.
Configure the following settings and select Register:
Name: Enter any application name (for example, PopTest01).
Supported account types: Accounts in any organizational directory (any Azure AD directory - multitenant).
Redirect URI: Select Public client/native (mobile & desktop) from the drop-down list and enter https://login.microsoftonline.com/common/oauth2/nativeclient.
Select Manage > Authentication.
Set Enable the following mobile and desktop flows to Yes.