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.7] Add options for SES Mailer #25536

Merged
merged 2 commits into from
Sep 10, 2018
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
51 changes: 43 additions & 8 deletions src/Illuminate/Mail/Transport/SesTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,24 @@ class SesTransport extends Transport
*/
protected $ses;

/**
* Transmission options.
*
* @var array
*/
protected $options = [];

/**
* Create a new SES transport instance.
*
* @param \Aws\Ses\SesClient $ses
* @param array $options
* @return void
*/
public function __construct(SesClient $ses)
public function __construct(SesClient $ses, $options = [])
{
$this->ses = $ses;
$this->options = $options;
}

/**
Expand All @@ -32,17 +41,43 @@ public function send(Swift_Mime_SimpleMessage $message, &$failedRecipients = nul
{
$this->beforeSendPerformed($message);

$headers = $message->getHeaders();
$result = $this->ses->sendRawEmail(
array_merge(
$this->options,
[
'Source' => key($message->getSender() ?: $message->getFrom()),
'RawMessage' => [
'Data' => $message->toString(),
],
]
)
);

$headers->addTextHeader('X-SES-Message-ID', $this->ses->sendRawEmail([
'Source' => key($message->getSender() ?: $message->getFrom()),
'RawMessage' => [
'Data' => $message->toString(),
],
])->get('MessageId'));
$message->getHeaders()->addTextHeader('X-SES-Message-ID', $result->get('MessageId'));

$this->sendPerformed($message);

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

/**
* Get the transmission options being used by the transport.
*
* @return array
*/
public function getOptions()
{
return $this->options;
}

/**
* Set the transmission options being used by the transport.
*
* @param array $options
* @return array
*/
public function setOptions(array $options)
{
return $this->options = $options;
}
}
7 changes: 4 additions & 3 deletions src/Illuminate/Mail/TransportManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,10 @@ protected function createSesDriver()
'version' => 'latest', 'service' => 'email',
]);

return new SesTransport(new SesClient(
$this->addSesCredentials($config)
));
return new SesTransport(
new SesClient($this->addSesCredentials($config)),
$config['options'] ?? []
);
}

/**
Expand Down