microsoftgraph / microsoftgraph/msgraph-sdk-php

The user account which was used to submit this request does not have the right to send mail on behalf of the specified sending account., Cannot submit message.ok

Open
#1,412 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
669
Forks
150
Avg merge
15h 21m
Merged PRs (30d)
3

Description

I try to send un email with ClientCredential and it doesn't work, i dont known if i do ther right thing :
Here is my code :

$tokenRequestContext = new ClientCredentialContext(
    'tenantId',
    'clientId',
    'secret'
);

$graphServiceClient = new GraphServiceClient($tokenRequestContext);

try {
    $sender = new EmailAddress();
    $sender->setAddress('john.doe@outlook.com');
    $sender->setName('John Doe');
    $fromRecipient = new Recipient();
    $fromRecipient->setEmailAddress($sender);

    $recipients = [];

    $recipientEmail = new EmailAddress();
    $recipientEmail->setAddress('jane.doe@outlook.com');
    $recipientEmail->setName('Jane Doe');
    $toRecipient = new Recipient();
    $toRecipient->setEmailAddress($recipientEmail);
    $recipients[] = $toRecipient;

    $emailBody = new ItemBody();
    $emailBody->setContent('Dummy content');
    $emailBody->setContentType(new BodyType(BodyType::TEXT));

    $message = new Message();
    $message->setSubject('Test Email');
    $message->setFrom($fromRecipient);
    $message->setToRecipients($recipients);
    $message->setBody($emailBody);

    $requestBody = new SendMailPostRequestBody();
    $requestBody->setMessage($message);

    /** @var UserItemRequestBuilder $user */
    $user = $graphServiceClient->users()->byUserId('userPrincipalName');
    $response = $user->sendMail()->post($requestBody)->wait();
    dump($response);

} catch (ApiException $ex) {
    echo $ex->getError()->getMessage();
}

I try to delegate right to send on userPrincipalName email but it doesn't work
i read doc lot of times and i don't understand why i doesn't work
I dont know if i can send an email like this with credential client account ?

Can you help me please ?
Thank you in advance

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the ClientCredentialContext setup and the users()->byUserId()->sendMail() request shown in the issue. Check the Microsoft Graph permissions and account configuration involved in sending on behalf of the specified user, then confirm the documented client-credential flow supports this request. Done means identifying the missing configuration or confirming a reproducible SDK defect.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
api, authorization
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.