I'm trying to connect to Exchange Online with MailKit.
I authenticate as application (using appl.id and secret).
I already have the code to retrieve the token (using Graph API)
But how do I authenticate the MailKit imapClient using the token?
If I want to authenticate a HttpClient I use:
_HttpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", AccessToken);
If I wanted to authenticate the MailKit imapClient using basic authentication it seems I could do:
using (var imapClient = new ImapClient())
{
imapClient.Connect("outlook.office365.com", 993, SecureSocketOptions.SslOnConnect);
imapClient.Authenticate("username", "password");
...
}
I have recently setup an application for this situation. The following is my code to connect to the exchange service using the appId, Client Secret, and TenantId. I also need to add you need to use the Microsoft Exchange web service to access the Microsoft Graph API (Where the app id and client secret was added in the cloud) because MailKit does not support it from what I know. You need to add the Microsoft.Exchange.WebServices dll from NuGet.