bug #37872 [Sendgrid-Mailer] Fixed envelope recipients on sendgridApiTransport (arendjantetteroo)

This PR was merged into the 4.4 branch.

Discussion
----------

[Sendgrid-Mailer] Fixed envelope recipients on sendgridApiTransport

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

Fixes #37870

The SendgridApiTransport was not using the envelope to get the
recipients, so overriding the recipients with the EnvelopeListener was
not working.

Commits
-------

c4e5131757 [Sendgrid-Mailer] Fixed envelope recipients on sendgridApiTransport
This commit is contained in:
Fabien Potencier 2020-08-18 12:13:56 +02:00
commit 5cbb019902
2 changed files with 31 additions and 1 deletions

View File

@ -192,4 +192,34 @@ class SendgridApiTransportTest extends TestCase
$this->assertArrayHasKey('email', $payload['reply_to']);
$this->assertSame($replyTo, $payload['reply_to']['email']);
}
public function testEnvelopeSenderAndRecipients()
{
$from = 'from@example.com';
$to = 'to@example.com';
$envelopeFrom = 'envelopefrom@example.com';
$envelopeTo = 'envelopeto@example.com';
$email = new Email();
$email->from($from)
->to($to)
->cc('cc@example.com')
->bcc('bcc@example.com')
->text('content');
$envelope = new Envelope(new Address($envelopeFrom), [new Address($envelopeTo)]);
$transport = new SendgridApiTransport('ACCESS_KEY');
$method = new \ReflectionMethod(SendgridApiTransport::class, 'getPayload');
$method->setAccessible(true);
$payload = $method->invoke($transport, $email, $envelope);
$this->assertArrayHasKey('from', $payload);
$this->assertArrayHasKey('email', $payload['from']);
$this->assertSame($envelopeFrom, $payload['from']['email']);
$this->assertArrayHasKey('personalizations', $payload);
$this->assertArrayHasKey('to', $payload['personalizations'][0]);
$this->assertArrayHasKey('email', $payload['personalizations'][0]['to'][0]);
$this->assertCount(1, $payload['personalizations'][0]['to']);
$this->assertSame($envelopeTo, $payload['personalizations'][0]['to'][0]['email']);
}
}

View File

@ -84,7 +84,7 @@ class SendgridApiTransport extends AbstractApiTransport
}
$personalization = [
'to' => array_map($addressStringifier, $email->getTo()),
'to' => array_map($addressStringifier, $this->getRecipients($email, $envelope)),
'subject' => $email->getSubject(),
];
if ($emails = array_map($addressStringifier, $email->getCc())) {