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

[10.x] throw TransportException instead of Exception in SES mail drivers #48645

Merged
merged 1 commit into from
Oct 5, 2023
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
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