8000 [Mailer] AWS SES transport Source ARN header support by chekalsky · Pull Request #40174 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Mailer] AWS SES transport Source ARN header support #40174

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

Merged
merged 1 commit into from
Feb 16, 2021
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.
Load 10000 ing
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public function testSend()
$this->assertSame('<b>Hello There!</b>', $content['Content']['Simple']['Body']['Html']['Data']);
$this->assertSame(['replyto-1@example.com', 'replyto-2@example.com'], $content['ReplyToAddresses']);
$this->assertSame('aws-configuration-set-name', $content['ConfigurationSetName']);
$this->assertSame('aws-source-arn', $content['FromEmailAddressIdentityArn']);
$this->assertSame('bounces@example.com', $content['FeedbackForwardingEmailAddress']);

$json = '{"MessageId": "foobar"}';
Expand All @@ -91,6 +92,7 @@ public function testSend()
->returnPath(new Address('bounces@example.com'));

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public function testSend()
$this->assertSame('Fabien <fabpot@symfony.com>', $content['Source']);
$this->assertSame('Hello There!', $content['Message_Body_Text_Data']);
$this->assertSame('aws-configuration-set-name', $content['ConfigurationSetName']);
$this->assertSame('aws-source-arn', $content['FromEmailAddressIdentityArn']);

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

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

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

Expand Down Expand Up @@ -135,6 +137,7 @@ public function testSendWithAttachments()
->attach('attached data');

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public function testSend()
$this->assertStringContainsString('Fabien <fabpot@symfony.com>', $content);
$this->assertStringContainsString('Hello There!', $content);
$this->assertSame('aws-configuration-set-name', $body['ConfigurationSetName']);
$this->assertSame('aws-source-arn', $body['FromEmailAddressIdentityArn']);

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

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

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public function testSend()
$this->assertStringContainsString('Hello There!', $content);

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

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

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ protected function getRequest(SentMessage $message): SendEmailRequest
if ($header = $email->getHeaders()->get('X-SES-CONFIGURATION-SET')) {
$request['ConfigurationSetName'] = $header->getBodyAsString();
}
if ($header = $email->getHeaders()->get('X-SES-SOURCE-ARN')) {
$request['FromEmailAddressIdentityArn'] = $header->getBodyAsString();
}
if ($email->getReturnPath()) {
$request['FeedbackForwardingEmailAddress'] = $email->getReturnPath()->toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ private function getPayload(Email $email, Envelope $envelope): array
$payload['ConfigurationSetName'] = $header->getBodyAsString();
}

if ($header = $email->getHeaders()->get('X-SES-SOURCE-ARN')) {
$payload['FromEmailAddressIdentityArn'] = $header->getBodyAsString();
}

return $payload;
}

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

return $payload;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ protected function getRequest(SentMessage $message): SendEmailRequest
&& $configurationSetHeader = $message->getOriginalMessage()->getHeaders()->get('X-SES-CONFIGURATION-SET')) {
$request['ConfigurationSetName'] = $configurationSetHeader->getBodyAsString();
}
if (($message->getOriginalMessage() instanceof Message)
&& $sourceArnHeader = $message->getOriginalMessage()->getHeaders()->get('X-SES-SOURCE-ARN')) {
$request['FromEmailAddressIdentityArn'] = $sourceArnHeader->getBodyAsString();
}

return new SendEmailRequest($request);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ protected function doSendHttp(SentMessage $message): ResponseInterface
$request['body']['ConfigurationSetName'] = $configurationSetHeader->getBodyAsString();
}

if ($message->getOriginalMessage() instanceof Message
&& $sourceArnHeader = $message->getOriginalMessage()->getHeaders()->get('X-SES-SOURCE-ARN')) {
$request['body']['FromEmailAddressIdentityArn'] = $sourceArnHeader->getBodyAsString();
}

$response = $this->client->request('POST', 'https://'.$this->getEndpoint(), $request);

$result = new \SimpleXMLElement($response->getContent(false));
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/Mailer/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ CHANGELOG
---

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

5.2.0
-----
Expand Down
0