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

- 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.
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.
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.
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.
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.
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.
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.

Consult the Microsoft Development Q&A Forum
If you experience specific exceptions while implementing OAuth 2.0, leverage the dedicated Microsoft development community for troubleshooting.
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. Download the Installer: Visit the official WPS Office website and click the free download button for your operating system.
- 2. Install the Suite: Run the downloaded executable file and follow the straightforward on-screen instructions.
- 3. Start Creating: Open WPS Office and instantly start editing your existing Microsoft Office files without any conversion issues.

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.




