From 3a178d98dcb2fd09a167315808acc53c18a06220 Mon Sep 17 00:00:00 2001 From: Cyril Mazur Date: Fri, 31 Mar 2017 13:29:05 +0200 Subject: [PATCH] Store the SparkPost transmission ID in the header X-SparkPost-Transmission-ID after the message has been sent --- .../Mail/Transport/SparkPostTransport.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Mail/Transport/SparkPostTransport.php b/src/Illuminate/Mail/Transport/SparkPostTransport.php index 6f3bab62bb92..3a889c137887 100644 --- a/src/Illuminate/Mail/Transport/SparkPostTransport.php +++ b/src/Illuminate/Mail/Transport/SparkPostTransport.php @@ -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, ], @@ -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); @@ -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. *