Microsoft Graph API Mail.Send Access Denied

Hector Espillco 6 Reputation points
2021-05-31T23:03:32.187+00:00

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
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,613 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Hector Espillco 6 Reputation points
    2021-06-01T04:19:14.79+00:00

    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.

    1 person found this answer helpful.
    0 comments No comments