skip to Main Content

I am trying to send an email using modern smtp with Office365 Graph API. Emails are sending fine, with attachments however, I cannot seem to fullfill the response I’m expecting from the endpoint.

$this->graphSdk->createRequest("POST", "/users/" . $this->config['from_email'] . "/sendmail")
    ->attachBody($this->getMessageBody($message))
    ->setReturnType(Message::class)
    ->execute()

The response when I dump and die is the following (the email successfully sends and I receive it):

MicrosoftGraphModelMessage {#4623
  #_propDict: []
}

I need to obtain both the message ID and conversation ID from this but I cannot seem to find any source of help from the documentation other than adding the associated return type which I have as the expected Message, any help appreciated.

2

Answers


  1. Microsoft Graph API does not return the message object or any response by default. It returns a 202 Accepted status code.

    Login or Signup to reply.
  2. First we save our data in a variable $response.

    $response = $this->graphSdk->createRequest("POST", "/users/" . $this->config['from_email'] . "/sendmail")
        ->attachBody($this->getMessageBody($message))
        ->setReturnType(Message::class)
        ->execute();
    

    now we get easily get id in $response variable.

    $messageId = $response->getId();
    

    Fetch Message By ID

    $message = $this->graphSdk->createRequest("GET", "/users/" . $this->config['from_email'] . "/messages/$messageId")
        ->setReturnType(Message::class)
        ->execute();
    

    If you have any query you may ask.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search