Exchange Connection Problems

Fix MailKit Microsoft 365 IMAP Login Failure in VB.NET

Muhammad TalhaMuhammad Talha Oct 28, 2026 869 views

Question details

The user needs to resolve an authentication failure when using MailKit in VB.NET to connect to a Microsoft 365 IMAP mailbox.

Fix MailKit Microsoft 365 IMAP Login Failure in VB.NET
Product
Microsoft 365
Device & OS
not provided
Scenario
Attempting to authenticate an IMAP connection to Exchange Online using MailKit in a VB.NET application.
Observed behavior
The IMAP login suddenly fails during application execution, despite the exact same credentials working correctly when logging into Outlook on the web.
Before you start

Ensure you have global administrator access to your Microsoft Entra ID (formerly Azure Active Directory) portal, as you will need to register an application to generate OAuth credentials.

Solution 1Recommended

Migrate to OAuth 2.0 Authentication for IMAP

Microsoft has deprecated and disabled Basic Authentication for Microsoft 365. You must update your MailKit VB.NET implementation to use modern OAuth 2.0 authentication.

Basic authentication uses just a username and password. Microsoft 365 now mandates modern authentication (OAuth 2.0) for IMAP protocols to prevent unauthorized access.

To restore connectivity, you need to acquire an access token using MSAL.NET and pass it to MailKit.

1
Register an Application in Microsoft Entra ID

Log in to the Microsoft Entra admin center, navigate to App registrations, and select 'New registration'. Note down your Application (client) ID and Directory (tenant) ID.

2
Configure API Permissions

In your newly registered app, go to 'API permissions' > 'Add a permission'. Select APIs my organization uses, search for 'Office 365 Exchange Online', and add the 'IMAP.AccessAsUser.All' delegated permission.

3
Generate a Client Secret

Navigate to 'Certificates & secrets' in the app menu. Create a new client secret and copy the value immediately for use in your VB.NET application.

4
Update MailKit Code in VB.NET

Use the Microsoft Authentication Library (MSAL) in your VB.NET project to fetch an OAuth token. Once obtained, instantiate MailKit's SaslMechanismOAuth2 object with the user's email address and the token, then pass it to the AuthenticateAsync method.

Migrate to OAuth 2.0 Authentication for IMAP
Admin Consent Required: Ensure that your Microsoft 365 administrator clicks 'Grant admin consent for [Organization]' in the API permissions tab, otherwise the application will fail to acquire the token.
Free Microsoft Office alternative

Looking for a Lightweight, Cost-Effective Office Suite?

While troubleshooting backend Exchange connections often requires complex Microsoft 365 configuration, your day-to-day document editing should be simple. WPS Office provides a highly compatible, resource-friendly, and free alternative for everyday productivity tasks.

  1. 1. Download the Installer: Visit the official WPS Office website and click the free download button for your operating system.
  2. 2. Install the Suite: Run the downloaded executable file and follow the straightforward on-screen instructions.
  3. 3. Start Creating: Open WPS Office and instantly start editing your existing Microsoft Office files without any conversion issues.
Fully compatible with Microsoft Word, Excel, and PowerPoint formats (.docx, .xlsx, .pptx)Significantly lighter on system resources compared to other major office suitesFamiliar user interface ensuring zero learning curveBuilt-in PDF editor and powerful cloud synchronization features
microsoft office alternative - wps office

Frequently Asked Questions

Why did my MailKit IMAP login suddenly stop working in Microsoft 365?

Microsoft has permanently disabled Basic Authentication for Exchange Online (IMAP/POP/SMTP). Applications passing a simple username and password will now be rejected by the server, even if those same credentials work when logging in via a web browser.

Does MailKit support OAuth 2.0 for Microsoft 365?

Yes, MailKit fully supports OAuth 2.0. You must use the SaslMechanismOAuth2 class to pass a valid access token retrieved via the Microsoft Authentication Library (MSAL).

How do I test if my OAuth token is valid for IMAP?

You can decode your JWT access token using tools like jwt.ms to verify that it contains the correct audience and scopes (such as IMAP.AccessAsUser.All) before you attempt to pass it to MailKit.

Can I re-enable Basic Authentication for my Microsoft 365 tenant?

No. Microsoft has completed the global deprecation of Basic Authentication for Exchange Online to improve baseline tenant security. All legacy IMAP, POP, and SMTP connections must be migrated to modern authentication.