bug #39743 [Mailer] Fix missing BCC recipients in SES bridge (jderusse)

This PR was merged into the 4.4 branch.

Discussion
----------

[Mailer] Fix missing BCC recipients in SES bridge

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #36333
| License       | MIT
| Doc PR        | -

When using the `ses` (alias of `ses+https`) scheme, the bridge send the RawEmail to AWS.
But RawEmails does not contains the BCC recipients.

This PR adds the envelope's recipients to the list of Destinations in Amazon SES payload.

Commits
-------

1cfc763018 Fix missing BCC recipients in SES bridge
This commit is contained in:
Nicolas Grekas 2021-01-12 12:30:25 +01:00
commit 6eff2630a1
2 changed files with 15 additions and 2 deletions

View File

@ -60,6 +60,12 @@ class SesHttpTransportTest extends TestCase
$this->assertStringContainsString('AWS3-HTTPS AWSAccessKeyId=ACCESS_KEY,Algorithm=HmacSHA256,Signature=', $options['headers'][0] ?? $options['request_headers'][0]);
parse_str($options['body'], $body);
$this->assertArrayHasKey('Destinations_member_1', $body);
$this->assertSame('saif.gmati@symfony.com', $body['Destinations_member_1']);
$this->assertArrayHasKey('Destinations_member_2', $body);
$this->assertSame('jeremy@derusse.com', $body['Destinations_member_2']);
$content = base64_decode($body['RawMessage_Data']);
$this->assertStringContainsString('Hello!', $content);
@ -83,6 +89,7 @@ class SesHttpTransportTest extends TestCase
$mail = new Email();
$mail->subject('Hello!')
->to(new Address('saif.gmati@symfony.com', 'Saif Eddin'))
->bcc(new Address('jeremy@derusse.com', 'Jérémy Derussé'))
->from(new Address('fabpot@symfony.com', 'Fabien'))
->text('Hello There!');

View File

@ -52,7 +52,7 @@ class SesHttpTransport extends AbstractHttpTransport
$date = gmdate('D, d M Y H:i:s e');
$auth = sprintf('AWS3-HTTPS AWSAccessKeyId=%s,Algorithm=HmacSHA256,Signature=%s', $this->accessKey, $this->getSignature($date));
$response = $this->client->request('POST', 'https://'.$this->getEndpoint(), [
$request = [
'headers' => [
'X-Amzn-Authorization' => $auth,
'Date' => $date,
@ -61,7 +61,13 @@ class SesHttpTransport extends AbstractHttpTransport
'Action' => 'SendRawEmail',
'RawMessage.Data' => base64_encode($message->toString()),
],
]);
];
$index = 1;
foreach ($message->getEnvelope()->getRecipients() as $recipient) {
$request['body']['Destinations.member.'.$index++] = $recipient->getAddress();
}
$response = $this->client->request('POST', 'https://'.$this->getEndpoint(), $request);
$result = new \SimpleXMLElement($response->getContent(false));
if (200 !== $response->getStatusCode()) {