Hi @James Sconfitto ,
Thanks for reaching out .
For client credentials flow, you need to add application permissions under Office 365 Exchange Online
Make sure to grant admin consent for all the application permissions.
Once consent has been provided, the admin must register your AAD application's service principal in Exchange using powerShell by following commands:
Install ExchangeOnlineManagement
Install-Module -Name ExchangeOnlineManagement -allowprerelease Import-module ExchangeOnlineManagement Connect-ExchangeOnline -Organization
Register Service Principal in Exchange:
1.New-ServicePrincipal -AppId <APPLICATION_ID> -ServiceId <OBJECT_ID> [-Organization <ORGANIZATION_ID>]
Make sure to use ObjectId from enterprise applications rather than object id of application registration. For the same application you registered in Application Registration. A corresponding application has been created in Enterprise Application as well. You need to pass object id from there while registering service principal in Exchange:
2.Get-ServicePrincipal | fl
3.Add-MailboxPermission -Identity "john.smith@contoso.com" -User <SERVICE_PRINCIPAL_ID> -AccessRights FullAccess
In the application, you need to use scope = 'https://outlook.office365.com/.default'
Once you get the access token, you can create and open a Mail connection to read mails.
Hope this will help.
Thanks,
Shweta
Please remember to "Accept Answer" if answer helped you.