0

My first question is whether or not this is even possible today? Half the stuff I'm reading suggests that the only way to get emails from Exchange anymore is Graph API.

Assuming that's not true, what is the way to get this working with the Mailkit library?

The most official documentation I could find is from the Mailkit github: https://github.com/jstedfast/MailKit/blob/master/ExchangeOAuth2.md

but this doesn't specify how to configure the app in Azure Active Directory.

This is what I setup: enter image description here

Using this app with the Powershell equivalent of the authentication from the Mailkit Github: ` $redirect_uri = 'https://login.microsoftonline.com/common/oauth2/nativeclient'

$options = [Microsoft.Identity.Client.PublicClientApplicationOptions]::new()
$options.ClientId = $ClientID
$options.TenantId = $TenantID
$options.RedirectUri = $redirect_uri

$scopes = New-Object System.Collections.Generic.List[string]
$scopes.Add("offline_access")
$scopes.Add("https://outlook.office.com/IMAP.AccessAsUser.All")
$scopes.Add("openid")
$scopes.Add("email")

$PublicClientApplication = [Microsoft.Identity.Client.PublicClientApplicationBuilder]::CreateWithApplicationOptions($options).Build()

$token = $PublicClientApplication.AcquireTokenByUsernamePassword($scopes, $mailbox,$pwd).ExecuteAsync()`

I get exception: "AADSTS7000218: The request body must contain the following parameter: 'client_assertion' or 'client_secret'."

I've also tried a different method from this video: https://www.youtube.com/watch?v=eDTO9W81P-Y

This uses a different scope and I'm actually able to retrieve the bearer token for this, however trying to authenticate to the IMAP client with that token gives me an "Authentication Failed"

Gstack
  • 1
  • 1
  • Does this answer your question? [Get-MsalToken error AADSTS7000218: The request body must contain the following parameter: 'client\_assertion' or 'client\_secret'](https://stackoverflow.com/questions/67573253/get-msaltoken-error-aadsts7000218-the-request-body-must-contain-the-following-p) – Eugene Astafiev Jun 25 '23 at 21:54
  • This seems to be exactly the second method I mention based off the Youtube tutorial. I'm still getting "Authentication Failed" for this. – Gstack Jun 27 '23 at 18:56

0 Answers0