Error accessing mail services using OAuth2


I’m trying to create imapClient providing access token (obtained by login with MSAL library) directly into the constructor of the client, but i get an error “Unable connect to the server”, why that happen?

I’m using the first example of this tutorial

image.png (13.6 KB)


Refer to the following article about prerequisite settings, getting a token using MSAL and connection using ImapClient. Thanks.

1 Like

Doesnt work with hotmail? Its only for microsoft365? This account have securities default enabled. As the server, i tried “” and “”, but it never works.

image.png (79.9 KB)


I assume this should work with hotmail.
You need to specify the TenantId as well:

var pca = PublicClientApplicationBuilder