Skip to content

Commit d7225db

Browse files
chekalskyfabpot
authored andcommitted
[Mailer] AWS SES transport Source ARN header support
1 parent c757845 commit d7225db

File tree

9 files changed

+29
-0
lines changed

9 files changed

+29
-0
lines changed

src/Symfony/Component/Mailer/Bridge/Amazon/Tests/Transport/SesApiAsyncAwsTransportTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public function testSend()
7070
$this->assertSame('<b>Hello There!</b>', $content['Content']['Simple']['Body']['Html']['Data']);
7171
$this->assertSame(['[email protected]', '[email protected]'], $content['ReplyToAddresses']);
7272
$this->assertSame('aws-configuration-set-name', $content['ConfigurationSetName']);
73+
$this->assertSame('aws-source-arn', $content['FromEmailAddressIdentityArn']);
7374
$this->assertSame('[email protected]', $content['FeedbackForwardingEmailAddress']);
7475

7576
$json = '{"MessageId": "foobar"}';
@@ -91,6 +92,7 @@ public function testSend()
9192
->returnPath(new Address('[email protected]'));
9293

9394
$mail->getHeaders()->addTextHeader('X-SES-CONFIGURATION-SET', 'aws-configuration-set-name');
95+
$mail->getHeaders()->addTextHeader('X-SES-SOURCE-ARN', 'aws-source-arn');
9496

9597
$message = $transport->send($mail);
9698

src/Symfony/Component/Mailer/Bridge/Amazon/Tests/Transport/SesApiTransportTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public function testSend()
6969
$this->assertSame('Fabien <[email protected]>', $content['Source']);
7070
$this->assertSame('Hello There!', $content['Message_Body_Text_Data']);
7171
$this->assertSame('aws-configuration-set-name', $content['ConfigurationSetName']);
72+
$this->assertSame('aws-source-arn', $content['FromEmailAddressIdentityArn']);
7273

7374
$xml = '<SendEmailResponse xmlns="https://email.amazonaws.com/doc/2010-03-31/">
7475
<SendEmailResult>
@@ -90,6 +91,7 @@ public function testSend()
9091
->text('Hello There!');
9192

9293
$mail->getHeaders()->addTextHeader('X-SES-CONFIGURATION-SET', 'aws-configuration-set-name');
94+
$mail->getHeaders()->addTextHeader('X-SES-SOURCE-ARN', 'aws-source-arn');
9395

9496
$message = $transport->send($mail);
9597

@@ -135,6 +137,7 @@ public function testSendWithAttachments()
135137
->attach('attached data');
136138

137139
$mail->getHeaders()->addTextHeader('X-SES-CONFIGURATION-SET', 'aws-configuration-set-name');
140+
$mail->getHeaders()->addTextHeader('X-SES-SOURCE-ARN', 'aws-source-arn');
138141

139142
$message = $transport->send($mail);
140143

src/Symfony/Component/Mailer/Bridge/Amazon/Tests/Transport/SesHttpAsyncAwsTransportTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public function testSend()
6969
$this->assertStringContainsString('Fabien <[email protected]>', $content);
7070
$this->assertStringContainsString('Hello There!', $content);
7171
$this->assertSame('aws-configuration-set-name', $body['ConfigurationSetName']);
72+
$this->assertSame('aws-source-arn', $body['FromEmailAddressIdentityArn']);
7273

7374
$json = '{"MessageId": "foobar"}';
7475

@@ -86,6 +87,7 @@ public function testSend()
8687
->text('Hello There!');
8788

8889
$mail->getHeaders()->addTextHeader('X-SES-CONFIGURATION-SET', 'aws-configuration-set-name');
90+
$mail->getHeaders()->addTextHeader('X-SES-SOURCE-ARN', 'aws-source-arn');
8991

9092
$message = $transport->send($mail);
9193

src/Symfony/Component/Mailer/Bridge/Amazon/Tests/Transport/SesHttpTransportTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public function testSend()
7777
$this->assertStringContainsString('Hello There!', $content);
7878

7979
$this->assertSame('aws-configuration-set-name', $body['ConfigurationSetName']);
80+
$this->assertSame('aws-source-arn', $body['FromEmailAddressIdentityArn']);
8081

8182
$xml = '<SendEmailResponse xmlns="https://email.amazonaws.com/doc/2010-03-31/">
8283
<SendRawEmailResult>
@@ -99,6 +100,7 @@ public function testSend()
99100
->text('Hello There!');
100101

101102
$mail->getHeaders()->addTextHeader('X-SES-CONFIGURATION-SET', 'aws-configuration-set-name');
103+
$mail->getHeaders()->addTextHeader('X-SES-SOURCE-ARN', 'aws-source-arn');
102104

103105
$message = $transport->send($mail);
104106

src/Symfony/Component/Mailer/Bridge/Amazon/Transport/SesApiAsyncAwsTransport.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ protected function getRequest(SentMessage $message): SendEmailRequest
9292
if ($header = $email->getHeaders()->get('X-SES-CONFIGURATION-SET')) {
9393
$request['ConfigurationSetName'] = $header->getBodyAsString();
9494
}
95+
if ($header = $email->getHeaders()->get('X-SES-SOURCE-ARN')) {
96+
$request['FromEmailAddressIdentityArn'] = $header->getBodyAsString();
97+
}
9598
if ($email->getReturnPath()) {
9699
$request['FeedbackForwardingEmailAddress'] = $email->getReturnPath()->toString();
97100
}

src/Symfony/Component/Mailer/Bridge/Amazon/Transport/SesApiTransport.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ private function getPayload(Email $email, Envelope $envelope): array
9999
$payload['ConfigurationSetName'] = $header->getBodyAsString();
100100
}
101101

102+
if ($header = $email->getHeaders()->get('X-SES-SOURCE-ARN')) {
103+
$payload['FromEmailAddressIdentityArn'] = $header->getBodyAsString();
104+
}
105+
102106
return $payload;
103107
}
104108

@@ -127,6 +131,9 @@ private function getPayload(Email $email, Envelope $envelope): array
127131
if ($header = $email->getHeaders()->get('X-SES-CONFIGURATION-SET')) {
128132
$payload['ConfigurationSetName'] = $header->getBodyAsString();
129133
}
134+
if ($header = $email->getHeaders()->get('X-SES-SOURCE-ARN')) {
135+
$payload['FromEmailAddressIdentityArn'] = $header->getBodyAsString();
136+
}
130137

131138
return $payload;
132139
}

src/Symfony/Component/Mailer/Bridge/Amazon/Transport/SesHttpAsyncAwsTransport.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ protected function getRequest(SentMessage $message): SendEmailRequest
8383
&& $configurationSetHeader = $message->getOriginalMessage()->getHeaders()->get('X-SES-CONFIGURATION-SET')) {
8484
$request['ConfigurationSetName'] = $configurationSetHeader->getBodyAsString();
8585
}
86+
if (($message->getOriginalMessage() instanceof Message)
87+
&& $sourceArnHeader = $message->getOriginalMessage()->getHeaders()->get('X-SES-SOURCE-ARN')) {
88+
$request['FromEmailAddressIdentityArn'] = $sourceArnHeader->getBodyAsString();
89+
}
8690

8791
return new SendEmailRequest($request);
8892
}

src/Symfony/Component/Mailer/Bridge/Amazon/Transport/SesHttpTransport.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ protected function doSendHttp(SentMessage $message): ResponseInterface
7777
$request['body']['ConfigurationSetName'] = $configurationSetHeader->getBodyAsString();
7878
}
7979

80+
if ($message->getOriginalMessage() instanceof Message
81+
&& $sourceArnHeader = $message->getOriginalMessage()->getHeaders()->get('X-SES-SOURCE-ARN')) {
82+
$request['body']['FromEmailAddressIdentityArn'] = $sourceArnHeader->getBodyAsString();
83+
}
84+
8085
$response = $this->client->request('POST', 'https://'.$this->getEndpoint(), $request);
8186

8287
$result = new \SimpleXMLElement($response->getContent(false));

src/Symfony/Component/Mailer/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
---
66

77
* added the `mailer` monolog channel and set it on all transport definitions
8+
* Add support for `X-SES-SOURCE-ARN` in `symfony/amazon-mailer`
89

910
5.2.0
1011
-----

0 commit comments

Comments
 (0)