"Access is denied. Check credentials and try again" error getting when try to send an email

Katya Fedorova 40 Reputation points
2023-08-28T09:31:49.1833333+00:00

Hello! I am begging for help with sending an email.
I am using Graph API for getting and sending email
I have the following permissions granted.
image

Please note that I need to send an email only as an authorized user with delegated permission, not with application permission.
With getting an email all good (hence I can say that the auth token is correct most likely). But when I am sending mail I get the error - "

Access is denied. Check credentials and try again.

My URL :
My URL :https://graph.microsoft.com/v1.0/users/******@gmail.com/sendMail

My body:

{
    "message": {
        "subject": "Meet for lunch? 2 ",
        "body": {
            "contentType": "Text",
            "content": "The new cafeteria ifsdfsdfss open."
        },
        "toRecipients": [
            {
                "emailAddress": {
                    "address": "******@gmail.com"
                }
            }
        ]
    }
}

My header:

Screenshot 2023-08-28 at 12.30.20

Please lend me your wisdom.

Microsoft Security | Microsoft Graph
0 comments No comments
{count} votes

Accepted answer
  1. CarlZhao-MSFT 46,376 Reputation points
    2023-08-29T03:26:24.9733333+00:00

    Hi @Katya Fedorova

    In the context of delegation, you can only send mail on behalf of the logged-in user (/me) and not other users. Before doing so, make sure you have obtained an access token using the delegated authentication flow (auth code flow or ROPC flow).

    User's image

    Hope this helps.

    If the reply is helpful, please click Accept Answer and kindly upvote it. If you have additional questions about this answer, please click Comment.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. msft-gu 1,355 Reputation points
    2023-08-29T01:10:56.9+00:00

    Hello Katya,

    Good day and thank you for the question. Can I please know if you're using user: sendMail? I also noticed that you're using "******@gmail.com". You may need to use [id] or [userPrincipalNam] under Exchange Online.

    For testing purposes, try using Graph Explorer and use sendMail endpoint using /me/sendMail and verify if it works.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.