0

I am developing a console app in .net which will send mail using the Azure AD application. I followed all the step from generating the certificates to registered an application in Azure AD. Then provided the application permission (Send mail as any user) using Microsoft graph API and provided it “grant permission” as an admin consent.

In my console app code I uses the below outlook api to send mail as resourseurl — https://outlook.office.com/api/v1.0/users/{my email account}/sendmail. After providing grant permission to my app I am still facing the 401:unauthorized error.

halfer
  • 19,824
  • 17
  • 99
  • 186
  • How do you send the authorization header? You might be interested in the [active directory authentication scenarios](https://learn.microsoft.com/en-us/azure/active-directory/develop/active-directory-authentication-scenarios#native-application-to-web-api) – user3151902 Aug 13 '17 at 09:36

1 Answers1

0

You gave permissions to Microsoft Graph API, so you need to use it.

https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/user_sendmail

The URL that you need to use is thus:

POST https://graph.microsoft.com/v1.0/users/{id | userPrincipalName}/sendMail

Internally the graph API does call the API you mentioned. But your token is for the graph. Not the outlook API.

You also mentioned the resource URL. The graph API resource URL is https://graph.microsoft.com.

juunas
  • 54,244
  • 13
  • 113
  • 149
  • Thanks for you post @juunas I do use this url as resourseurl  "https://graph.microsoft.com/v1.0/users/{id | userPrincipalName}/sendMail", But still I am facing the 401-unauthorized issue. – Arpa Sen Aug 14 '17 at 10:14
  • You are going to have to add code that you are using to get the token to your question. Obviously something is wrong with the access token or you are adding it to the request wrong. – juunas Aug 14 '17 at 16:10