Generating Reply Email via MSGraph PHP SDK

DinosaurHunter :

I am rebuilding an EWS-based system to use the Microsoft Graph REST API and I am having trouble replicating the Reply Email functionality as I had in the EWS implementation.


With EWS I would create a ReplyToItemType, specify the original email and attach the NewBodyContent like so:

$reply = new ReplyToItemType();

$reply->ReferenceItemId = new ItemIdType();
$reply->ReferenceItemId->Id = $this->message->ItemId->Id;
$reply->ReferenceItemId->ChangeKey = $this->message->ItemId->ChangeKey;

$reply->NewBodyContent = new BodyType();
$reply->NewBodyContent->BodyType = BodyTypeType::HTML;
$reply->NewBodyContent->_ = $this->body;

This would create a new message with the content of the previous email already attached and set the subject (i.e. "RE: original subject")


With MSGraph, I don't seem to be able to replicate this functionality...

I am using the POST /users/{id | userPrincipalName}/messages/{id}/reply endpoint (so specifies the message to reply to in the URL):

$this->graph = new Graph();
$this->graph->setAccessToken($token);

$graphRequest = $this->graph->createRequest(
    'POST', '/users/' . $mailbox . '/messages/' . $exchange_id . '/reply'
);

$graphRequest->attachBody($body)->execute();

The request body, $body, looks like:

array:1 [
  "Message" => array:6 [
    "sender" => array:1 [
      "emailAddress" => array:1 [
        "address" => "[email protected]"
      ]
    ]
    "toRecipients" => array:1 [
      0 => array:1 [
        "emailAddress" => array:1 [
          "address" => "[email protected]"
        ]
      ]
    ]
    "ccRecipients" => []
    "attachments" => []
    "body" => array:2 [
      "contentType" => "html"
      "content" => "<p>Test</p>"
    ]
    "subject" => "null"
  ]
]

But that sends an email with a subject "null" and with the content:

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
    </head>
    <body>
        <p>test</p>
    </body>
</html>

Is there any way of replicating the EWS functionality as above, without having to attach the previous email content and subject manually?

Josh :

Instead of constructing a message object, you're going to want to use the comment property instead. Set it to a text string and it will become the top part of the reply message, with the quoted text from the original message appearing underneath as you would expect.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=294001&siteId=1