We are using Mail.dll to read messages using IMAP. The mailbox is an office 365 email box.
We are trying to migrate to oauth2 as basic authentication is getting deprecated.
We have followed the following article to the letter:
https://www.limilabs.com/blog/oauth2-client-credential-flow-office365-exchange-imap-pop3-smtp
The access token gets generated successfully.
However we are getting an exception with a message "AUTHENTICATE failed"
Code:
var app = ConfidentialClientApplicationBuilder
.Create(clientId)
.WithTenantId(tenantId)
.WithClientSecret(clientSecret)
.Build();
string[] scopes = new string[] {
"https://outlook.office365.com/.default"
};
var result = await app.AcquireTokenForClient(scopes)
.ExecuteAsync();
string accessToken = result.AccessToken;
Console.WriteLine(accessToken);
using (Imap client = new Imap())
{
client.ConnectSSL("outlook.office365.com");
client.LoginOAUTH2(userEmail, accessToken);
client.Close();
}
We did a lot of research and browsing through the forums before asking this question.
Our Microsoft 365 admin also went through this checklist:
https://www.limilabs.com/blog/office365-enable-imap-pop3-smtp
But we are still getting the issue after ensuring everything in your instructions was applied.
Please advise.