Skip to content

Commit

Permalink
[9.x] Sesv2client (#37878)
Browse files Browse the repository at this point in the history
* update SesTransport to use SesV2Client

* update tests for SesV2Client usage
  • Loading branch information
fideloper authored Jul 1, 2021
1 parent b52f82c commit fb33213
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/Illuminate/Mail/MailManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Illuminate\Mail;

use Aws\Ses\SesClient;
use Aws\SesV2\SesV2Client;
use Closure;
use GuzzleHttp\Client as HttpClient;
use Illuminate\Contracts\Mail\Factory as FactoryContract;
Expand Down Expand Up @@ -271,7 +271,7 @@ protected function createSesTransport(array $config)
$config = Arr::except($config, ['transport']);

return new SesTransport(
new SesClient($this->addSesCredentials($config)),
new SesV2Client($this->addSesCredentials($config)),
$config['options'] ?? []
);
}
Expand Down
14 changes: 7 additions & 7 deletions src/Illuminate/Mail/Transport/SesTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

namespace Illuminate\Mail\Transport;

use Aws\Ses\SesClient;
use Aws\SesV2\SesV2Client;
use Swift_Mime_SimpleMessage;

class SesTransport extends Transport
{
/**
* The Amazon SES instance.
*
* @var \Aws\Ses\SesClient
* @var \Aws\SesV2\SesV2Client
*/
protected $ses;

Expand All @@ -24,11 +24,11 @@ class SesTransport extends Transport
/**
* Create a new SES transport instance.
*
* @param \Aws\Ses\SesClient $ses
* @param \Aws\SesV2\SesV2Client $ses
* @param array $options
* @return void
*/
public function __construct(SesClient $ses, $options = [])
public function __construct(SesV2Client $ses, $options = [])
{
$this->ses = $ses;
$this->options = $options;
Expand All @@ -41,10 +41,10 @@ public function send(Swift_Mime_SimpleMessage $message, &$failedRecipients = nul
{
$this->beforeSendPerformed($message);

$result = $this->ses->sendRawEmail(
$result = $this->ses->sendEmail(
array_merge(
$this->options, [
'Source' => key($message->getSender() ?: $message->getFrom()),
'FromEmailAddress' => key($message->getSender() ?: $message->getFrom()),
'RawMessage' => [
'Data' => $message->toString(),
],
Expand All @@ -65,7 +65,7 @@ public function send(Swift_Mime_SimpleMessage $message, &$failedRecipients = nul
/**
* Get the Amazon SES client for the SesTransport instance.
*
* @return \Aws\Ses\SesClient
* @return \Aws\SesV2\SesV2Client
*/
public function ses()
{
Expand Down
14 changes: 7 additions & 7 deletions tests/Mail/MailSesTransportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Illuminate\Tests\Mail;

use Aws\Ses\SesClient;
use Aws\SesV2\SesV2Client;
use Illuminate\Config\Repository;
use Illuminate\Container\Container;
use Illuminate\Mail\MailManager;
Expand Down Expand Up @@ -46,8 +46,8 @@ public function testSend()
$message->setTo('me@example.com');
$message->setBcc('you@example.com');

$client = $this->getMockBuilder(SesClient::class)
->addMethods(['sendRawEmail'])
$client = $this->getMockBuilder(SesV2Client::class)
->addMethods(['sendEmail'])
->disableOriginalConstructor()
->getMock();
$transport = new SesTransport($client);
Expand All @@ -57,9 +57,9 @@ public function testSend()
$messageId = Str::random(32);
$sendRawEmailMock = new sendRawEmailMock($messageId);
$client->expects($this->once())
->method('sendRawEmail')
->method('sendEmail')
->with($this->equalTo([
'Source' => 'myself@example.com',
'FromEmailAddress' => 'myself@example.com',
'RawMessage' => ['Data' => (string) $message],
]))
->willReturn($sendRawEmailMock);
Expand All @@ -83,7 +83,7 @@ public function testSesLocalConfiguration()
'region' => 'eu-west-1',
'options' => [
'ConfigurationSetName' => 'Laravel',
'Tags' => [
'EmailTags' => [
['Name' => 'Laravel', 'Value' => 'Framework'],
],
],
Expand Down Expand Up @@ -116,7 +116,7 @@ public function testSesLocalConfiguration()

$this->assertSame([
'ConfigurationSetName' => 'Laravel',
'Tags' => [
'EmailTags' => [
['Name' => 'Laravel', 'Value' => 'Framework'],
],
], $transport->getOptions());
Expand Down

0 comments on commit fb33213

Please sign in to comment.