0 votes

We are trying to log into the appreg using the following but it seems to be erroring out and say Limilabs.Client.IMAP.ImapResponseException: 'AUTHENTICATE failed.'

IConfidentialClientApplication app;

app = ConfidentialClientApplicationBuilder.Create(clientID)

var result = await app.AcquireTokenForClient(scopes)

using (Imap client = new Imap())
    client.LoginOAUTH2(userEmail, result.AccessToken);


    var count = client.CurrentFolder.MessageCount;
    Console.WriteLine( count + " message(s) in Inbox");


Please let us know if this is supported.

by (210 points)

1 Answer

+1 vote

Mail.dll supports OAuth2. The problem you might be facing here is on the Office365 side: I think Office365 doesn't allow using ConfidentialClient with IMAP.

I'm not sure about it to be honest, but it seems that Exchange/Office365 doesn't support 'OAuth2 client credentials grant flow'.

It supports 'OAuth2 authorization code flow' and 'OAuth2 Device authorization grant flow' only - access token on behalf of a user flows.

Please contact Office365 support for clarification.


Consider using password grant flow:




by (298k points)