Skip to content

Commit

Permalink
Merge pull request #28994 from CyrilMazur/5.8-mailgun-message-id
Browse files Browse the repository at this point in the history
[5.8] Storing Mailgun Message-ID in the headers after sending
  • Loading branch information
taylorotwell committed Jul 1, 2019
2 parents 2dbe435 + a7fbb20 commit c7f7c1a
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/Illuminate/Mail/Transport/MailgunTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,16 @@ public function send(Swift_Mime_SimpleMessage $message, &$failedRecipients = nul

$message->setBcc([]);

$this->client->request(
$response = $this->client->request(
'POST',
"https://{$this->endpoint}/v3/{$this->domain}/messages.mime",
$this->payload($message, $to)
);

$message->getHeaders()->addTextHeader(
'X-Mailgun-Message-ID', $this->getMessageId($response)
);

$this->sendPerformed($message);

return $this->numberOfRecipients($message);
Expand Down Expand Up @@ -129,6 +133,19 @@ protected function allContacts(Swift_Mime_SimpleMessage $message)
);
}

/**
* Get the message ID from the response.
*
* @param \Psr\Http\Message\ResponseInterface $response
* @return string
*/
protected function getMessageId($response)
{
return object_get(
json_decode($response->getBody()->getContents()), 'id'
);
}

/**
* Get the API key being used by the transport.
*
Expand Down

0 comments on commit c7f7c1a

Please sign in to comment.