Skip to content

Commit

Permalink
Store the SparkPost transmission ID in the header X-SparkPost-Transmi…
Browse files Browse the repository at this point in the history
…ssion-ID after the message has been sent
  • Loading branch information
CyrilMazur committed Mar 31, 2017
1 parent d3c9668 commit 3a178d9
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/Illuminate/Mail/Transport/SparkPostTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function send(Swift_Mime_Message $message, &$failedRecipients = null)

$message->setBcc([]);

$this->client->post('https://api.sparkpost.com/api/v1/transmissions', [
$response = $this->client->post('https://api.sparkpost.com/api/v1/transmissions', [
'headers' => [
'Authorization' => $this->key,
],
Expand All @@ -66,6 +66,8 @@ public function send(Swift_Mime_Message $message, &$failedRecipients = null)
], $this->options),
]);

$message->getHeaders()->addTextHeader('X-SparkPost-Transmission-ID', $this->getTransmissionId($response));

$this->sendPerformed($message);

return $this->numberOfRecipients($message);
Expand Down Expand Up @@ -98,6 +100,19 @@ protected function getRecipients(Swift_Mime_Message $message)
return $recipients;
}

/**
* Get the transmission ID from the response.
*
* @param \GuzzleHttp\Psr7\Response $response
* @return string
*/
protected function getTransmissionId($response)
{
$result = json_decode($response->getBody()->getContents());

return object_get($result, 'results.id');
}

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

0 comments on commit 3a178d9

Please sign in to comment.