microsoftgraph / msgraph-sdk-php

Microsoft Graph Library for PHP.
Other
551 stars 141 forks source link

Sending email : "403 Forbidden" Only for MIME message #1499

Open francescodiperna opened 2 months ago

francescodiperna commented 2 months ago

Hi, I'm using the version 1.110. I have the following error trying to send an email in MIME type:

Client error: `POST https://graph.microsoft.com/v1.0/users/[EMAIL_ADDRESS]/sendMail` resulted in a `403 Forbidden` response:
{"error":{"code":"ErrorSendAsDenied","message":"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."}}

The code used to send is the following:

$requestUrl = '/users/' . $username . '/sendMail';        
        $emailResponse = $this->graphClient->createRequest('POST', $requestUrl)
            ->addHeaders(["Content-Type" => "text/plain"])
            ->attachBody(base64_encode(serialize([
                "Content-Type" => "text/plain",
                'message' => $mimeContent
            ])))->execute();

With the same email account, if I send an email in Json format I do not have any error.

Any Idea how to solve? Thanks

Francesco