Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.3] Storing SES Message-ID in the headers after sending #16366

Merged
merged 2 commits into from
Nov 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Illuminate/Mail/Transport/LogTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public function send(Swift_Mime_Message $message, &$failedRecipients = null)

$this->logger->debug($this->getMimeEntityString($message));

$this->sendPerformed($message);

return $this->numberOfRecipients($message);
}

Expand Down
2 changes: 2 additions & 0 deletions src/Illuminate/Mail/Transport/MailgunTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ public function send(Swift_Mime_Message $message, &$failedRecipients = null)

$this->client->post($this->url, $options);

$this->sendPerformed($message);

return $this->numberOfRecipients($message);
}

Expand Down
2 changes: 2 additions & 0 deletions src/Illuminate/Mail/Transport/MandrillTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public function send(Swift_Mime_Message $message, &$failedRecipients = null)

$this->client->post('https://mandrillapp.com/api/1.0/messages/send-raw.json', $options);

$this->sendPerformed($message);

return $this->numberOfRecipients($message);
}

Expand Down
9 changes: 7 additions & 2 deletions src/Illuminate/Mail/Transport/SesTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,17 @@ 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);

return $this->numberOfRecipients($message);
}
Expand Down
2 changes: 2 additions & 0 deletions src/Illuminate/Mail/Transport/SparkPostTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ public function send(Swift_Mime_Message $message, &$failedRecipients = null)

$this->client->post('https://api.sparkpost.com/api/v1/transmissions', $options);

$this->sendPerformed($message);

return $this->numberOfRecipients($message);
}

Expand Down
18 changes: 18 additions & 0 deletions src/Illuminate/Mail/Transport/Transport.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,24 @@ protected function beforeSendPerformed(Swift_Mime_Message $message)
}
}

/**
* Iterate through registered plugins and execute plugins' methods.
*
* @param \Swift_Mime-Message $message
* @return void
*/
protected function sendPerformed(Swift_Mime_Message $message)
{

$event = new Swift_Events_SendEvent($this, $message);

foreach ($this->plugins as $plugin) {
if (method_exists($plugin, 'sendPerformed')) {
$plugin->sendPerformed($event);
}
}
}

/**
* Get the number of recipients.
*
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;
}
}