Fix missing BCC recipients in SES bridge

This commit is contained in:
Jérémy Derussé 2021-01-07 00:10:20 +01:00
parent 92ccb0a9df
commit 1cfc763018
No known key found for this signature in database
GPG Key ID: 2083FA5758C473D2
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()) {