Scenario: Console application needs to send an email from defined mailbox. All setup in Azure is done and application has access and all works well in Postman.
Question is how to do the same with Microsoft libraries - especially with GraphServiceClient.
Note: example is not showing message body as it is not relevant for the question.
Raw request
POST https://graph.microsoft.com/v1.0/users/<email-address>/sendMail
.NET code
IConfidentialClientApplication confidentialClientApplication = ConfidentialClientApplicationBuilder
.Create(clientId)
.WithAuthority(AzureCloudInstance.AzurePublic, tenantId)
.WithClientSecret(secret)
.Build();
ClientCredentialProvider authProvider = new ClientCredentialProvider(confidentialClientApplication);
GraphServiceClient graphClient = new GraphServiceClient(authProvider);
await graphClient.Me
.SendMail(message, saveToSentItems)
.Request()
.PostAsync();