Not able to send email

Shahid 6 Reputation points
2022-09-07T06:41:34.543+00:00

Hi,

I am trying to send an email using graph api with client credentials flow. App registration and app permission already configured as per# https://learn.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-client-creds-grant-flow.

I am getting auth token but using that token when i tried sending email , it responds back with invalid user whereas that user exist.

{
"error": {
"code": "ErrorInvalidUser",
"message": "The requested user '<<userid>> is invalid.",
"innerError": {
"date": "2022-09-07T05:22:38",
"request-id": "a21a880b-efb5-47ae-81d8-6d6af5ece6bf",
"client-request-id": "a21a880b-efb5-47ae-81d8-6d6af5ece6bf"
}
}
}

Below are the permission given:

Mail.Send. (application)

User.Read. (Delegated)

User.Read.All (application)

if i tried same endpoint by taking token from graph explorer interface then it works.
Could you please help me to know what i am missing here?

Thanks ,
Shahid

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,591 questions
{count} vote

2 answers

Sort by: Most helpful
  1. Zehui Yao_MSFT 5,831 Reputation points
    2022-09-08T06:45:18.953+00:00

    Hi @Shahid , I tested locally and can run successfully. Since explorer, the default is to get tokens with OAuth 2.0 authorization code grant flow instead of client credentials flow,
    so I'm not sure if you got the token correctly.
    You can refer to this documentation to get a token. Hope this can help you. Best Regards.
    238858-untitled4.png

    238951-image.png
    238934-image.png


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  2. sanjay mallik 1 Reputation point
    2022-10-20T13:35:41.983+00:00

    Hi @Zehui Yao_MSFT ,

    I was also facing the same issues what you have discussed in the above conversation, I followed all your suggestion and now client credential flow is working for me. Thanks a lot for your suggestions.

    0 comments No comments