Skip to content

Commit

Permalink
throw TransportException instead of Exception in SES and SES v2 mail …
Browse files Browse the repository at this point in the history
…driver (#48645)
  • Loading branch information
bchalier authored Oct 5, 2023
1 parent 9451a9e commit 4a9ae49
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/Illuminate/Mail/Transport/SesTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Aws\Exception\AwsException;
use Aws\Ses\SesClient;
use Exception;
use Symfony\Component\Mailer\Exception\TransportException;
use Symfony\Component\Mailer\Header\MetadataHeader;
use Symfony\Component\Mailer\SentMessage;
use Symfony\Component\Mailer\Transport\AbstractTransport;
Expand Down Expand Up @@ -75,7 +75,7 @@ protected function doSend(SentMessage $message): void
} catch (AwsException $e) {
$reason = $e->getAwsErrorMessage() ?? $e->getMessage();

throw new Exception(
throw new TransportException(
sprintf('Request to AWS SES API failed. Reason: %s.', $reason),
is_int($e->getCode()) ? $e->getCode() : 0,
$e
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Mail/Transport/SesV2Transport.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Aws\Exception\AwsException;
use Aws\SesV2\SesV2Client;
use Exception;
use Symfony\Component\Mailer\Exception\TransportException;
use Symfony\Component\Mailer\Header\MetadataHeader;
use Symfony\Component\Mailer\SentMessage;
use Symfony\Component\Mailer\Transport\AbstractTransport;
Expand Down Expand Up @@ -79,7 +79,7 @@ protected function doSend(SentMessage $message): void
} catch (AwsException $e) {
$reason = $e->getAwsErrorMessage() ?? $e->getMessage();

throw new Exception(
throw new TransportException(
sprintf('Request to AWS SES V2 API failed. Reason: %s.', $reason),
is_int($e->getCode()) ? $e->getCode() : 0,
$e
Expand Down
20 changes: 20 additions & 0 deletions tests/Mail/MailSesTransportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Illuminate\Tests\Mail;

use Aws\Command;
use Aws\Exception\AwsException;
use Aws\Ses\SesClient;
use Illuminate\Config\Repository;
use Illuminate\Container\Container;
Expand All @@ -10,6 +12,7 @@
use Illuminate\View\Factory;
use Mockery as m;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Mailer\Exception\TransportException;
use Symfony\Component\Mailer\Header\MetadataHeader;
use Symfony\Component\Mime\Address;
use Symfony\Component\Mime\Email;
Expand Down Expand Up @@ -78,6 +81,23 @@ public function testSend()
(new SesTransport($client))->send($message);
}

public function testSendError()
{
$message = new Email();
$message->subject('Foo subject');
$message->text('Bar body');
$message->sender('myself@example.com');
$message->to('me@example.com');

$client = m::mock(SesClient::class);
$client->shouldReceive('sendRawEmail')->once()
->andThrow(new AwsException('Email address is not verified.', new Command('sendRawEmail')));

$this->expectException(TransportException::class);

(new SesTransport($client))->send($message);
}

public function testSesLocalConfiguration()
{
$container = new Container;
Expand Down
20 changes: 20 additions & 0 deletions tests/Mail/MailSesV2TransportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Illuminate\Tests\Mail;

use Aws\Command;
use Aws\Exception\AwsException;
use Aws\SesV2\SesV2Client;
use Illuminate\Config\Repository;
use Illuminate\Container\Container;
Expand All @@ -10,6 +12,7 @@
use Illuminate\View\Factory;
use Mockery as m;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Mailer\Exception\TransportException;
use Symfony\Component\Mailer\Header\MetadataHeader;
use Symfony\Component\Mime\Address;
use Symfony\Component\Mime\Email;
Expand Down Expand Up @@ -78,6 +81,23 @@ public function testSend()
(new SesV2Transport($client))->send($message);
}

public function testSendError()
{
$message = new Email();
$message->subject('Foo subject');
$message->text('Bar body');
$message->sender('myself@example.com');
$message->to('me@example.com');

$client = m::mock(SesV2Client::class);
$client->shouldReceive('sendEmail')->once()
->andThrow(new AwsException('Email address is not verified.', new Command('sendRawEmail')));

$this->expectException(TransportException::class);

(new SesV2Transport($client))->send($message);
}

public function testSesV2LocalConfiguration()
{
$container = new Container;
Expand Down

0 comments on commit 4a9ae49

Please sign in to comment.