question

HectorEspillco-1931 avatar image
0 Votes"
HectorEspillco-1931 asked HectorEspillco-1931 answered

Microsoft Graph API Mail.Send Access Denied

I am having problems to send mails using Microsoft Graph.

I did the following:

  1. I created an app of type : Multiple organizations

  2. After that, I created a secret in my App.

  3. Later, I added the following permissions:

101231-image.png


This permissions was aproved by an admin.

  1. I get a token using the following code:

var clientSecret = @"{My generated Secret in Azure}";
var clientId = @"{My Client Id}";
var tenantID = @"{My Tenant Id}";
IConfidentialClientApplication app= ConfidentialClientApplicationBuilder
.Create(clientId)
.WithTenantId(tenantID)
.WithClientSecret(clientSecret)
.Build();

result = await app.AcquireTokenForClient(scopes)
.ExecuteAsync();

  1. With this token I did a call to the api https://graph.microsoft.com/v1.0/me/sendMail from postman to test the token,but postman is returning this error:

{
"error": {
"code": "ErrorAccessDenied",
"message": "Access is denied. Check credentials and try again."
}
}

IS there some additional configuration or miss configuration I am doing?

These are the values of the token:

101187-image.png


microsoft-graph-mail
image.png (10.2 KiB)
image.png (47.9 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

HectorEspillco-1931 avatar image
1 Vote"
HectorEspillco-1931 answered

I found the problem, I was using an incorrect url.

For the case of Applications permissions we must use https://graph.microsoft.com/v1.0/users/{userId}/sendMail.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.