Skip to content

Commit

Permalink
Store the SES message ID in the header X-SES-Message-ID after the mes…
Browse files Browse the repository at this point in the history
…sage has been sent.
  • Loading branch information
Jon Baker committed Nov 11, 2016
1 parent 8eabb73 commit c15e114
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/Illuminate/Mail/Transport/SesTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,15 @@ public function send(Swift_Mime_Message $message, &$failedRecipients = null)
{
$this->beforeSendPerformed($message);

$this->ses->sendRawEmail([
$headers = $message->getHeaders();

// Send the message to SES, storing the SES message id in X-SES-Message-ID
$headers->addTextHeader('X-SES-Message-ID',$this->ses->sendRawEmail([
'Source' => key($message->getSender() ?: $message->getFrom()),
'RawMessage' => [
'Data' => $message->toString(),
],
]);
])->get('MessageId'));

$this->sendPerformed($message);

Expand Down
28 changes: 27 additions & 1 deletion tests/Mail/MailSesTransportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,39 @@ public function testSend()
->getMock();
$transport = new SesTransport($client);

// Generate a messageId for our mock to return to ensure that the post-sent message
// has X-SES-Message-ID in its headers
$messageId = str_random(32);
$sendRawEmailMock = new sendRawEmailMock($messageId);
$client->expects($this->once())
->method('sendRawEmail')
->with($this->equalTo([
'Source' => 'myself@example.com',
'RawMessage' => ['Data' => (string) $message],
]));
]))
->willReturn($sendRawEmailMock);

$transport->send($message);
$this->assertEquals($messageId, $message->getHeaders()->get('X-SES-Message-ID')->getFieldBody());
}
}

class sendRawEmailMock {

protected $getResponse = null;

public function __construct($responseValue)
{
$this->getResponse = $responseValue;
}

/**
* Mock the get() call for the sendRawEmail response
* @param [type] $key [description]
* @return [type] [description]
*/
public function get($key)
{
return $this->getResponse;
}
}

0 comments on commit c15e114

Please sign in to comment.