Skip to content
Closed
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
5 changes: 3 additions & 2 deletions src/Illuminate/Mail/MailManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Log\LogManager;
use Illuminate\Mail\Transport\ArrayTransport;
use Illuminate\Mail\Transport\LogTransport;
use Illuminate\Mail\Transport\SesTransport;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use InvalidArgumentException;
Expand Down Expand Up @@ -240,14 +241,14 @@ protected function createSesTransport(array $config)
$config['session_token'] = $config['token'];
}

return $factory->create(new Dsn(
return new SesTransport($factory->create(new Dsn(
'ses+api',
'default',
$config['key'] ?? null,
$config['secret'] ?? null,
$config['port'] ?? null,
$config
));
)), $config['options'] ?? []);
}

/**
Expand Down
2 changes: 0 additions & 2 deletions src/Illuminate/Mail/Transport/ArrayTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ public function __construct()

/**
* {@inheritdoc}
*
* @return int
*/
public function send(RawMessage $message, Envelope $envelope = null): ?SentMessage
{
Expand Down
2 changes: 0 additions & 2 deletions src/Illuminate/Mail/Transport/LogTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ public function __construct(LoggerInterface $logger)

/**
* {@inheritdoc}
*
* @return int
*/
public function send(RawMessage $message, Envelope $envelope = null): ?SentMessage
{
Expand Down
101 changes: 101 additions & 0 deletions src/Illuminate/Mail/Transport/SesTransport.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?php

namespace Illuminate\Mail\Transport;

use InvalidArgumentException;
use Symfony\Component\Mailer\Bridge\Amazon\Transport\SesApiAsyncAwsTransport;
use Symfony\Component\Mailer\Bridge\Amazon\Transport\SesHttpAsyncAwsTransport;
use Symfony\Component\Mailer\Envelope;
use Symfony\Component\Mailer\SentMessage;
use Symfony\Component\Mailer\Transport\TransportInterface;
use Symfony\Component\Mime\Email;
use Symfony\Component\Mime\RawMessage;

class SesTransport implements TransportInterface
{
/**
* The Amazon SES Symfony transport.
*
* @var \Symfony\Component\Mailer\Bridge\Amazon\Transport\SesApiAsyncAwsTransport|\Symfony\Component\Mailer\Bridge\Amazon\Transport\SesHttpAsyncAwsTransport
*/
protected $transport;

/**
* The Amazon SES transmission options.
*
* @var array
*/
protected $options;

/**
* Create a new SES transport instance.
*
* @param \Symfony\Component\Mailer\Bridge\Amazon\Transport\SesApiAsyncAwsTransport|\Symfony\Component\Mailer\Bridge\Amazon\Transport\SesHttpAsyncAwsTransport $transport
* @param array $options
* @return void
*/
public function __construct(TransportInterface $transport, array $options = [])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since Laravel 9 requires PHP 8, couldn't the type-hint here be SesApiAsyncAwsTransport|SesHttpAsyncAwsTransport instead and remove the exception below?

{
if (! $transport instanceof SesApiAsyncAwsTransport || ! $transport instanceof SesHttpAsyncAwsTransport) {
throw new InvalidArgumentException(
'The SesTransport only accepts a SesHttpAsyncAwsTransport or a SesApiAsyncAwsTransport.'
);
}

$this->transport = $transport;
$this->options = $options;
}

/**
* {@inheritdoc}
*/
public function send(RawMessage $message, ?Envelope $envelope = null): ?SentMessage
{
if ($message instanceof Email) {
if (isset($this->options['ConfigurationSetName'])) {
$message->getHeaders()->addTextHeader(
'X-SES-CONFIGURATION-SET', $this->options['ConfigurationSetName']
);
}

if (isset($this->options['FromEmailAddressIdentityArn'])) {
$message->getHeaders()->addTextHeader(
'X-SES-SOURCE-ARN', $this->options['FromEmailAddressIdentityArn']
);
}
}

return $this->transport->send($message, $envelope);
}

/**
* Get the string representation of the transport.
*
* @return string
*/
public function __toString(): string
{
return $this->transport->__toString();
}

/**
* 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;
}
}