Skip to content

Commit 7ca45f1

Browse files
committed
Don't duplicate addresses in Sendgrid Transport
1 parent 3f467f7 commit 7ca45f1

File tree

3 files changed

+123
-1
lines changed

3 files changed

+123
-1
lines changed

Sendgrid/Http/Api/SendgridTransport.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ private function getPayload(Email $email, SmtpEnvelope $envelope): array
6767
}
6868

6969
$personalization = [
70-
'to' => array_map($addressStringifier, $this->getRecipients($email, $envelope)),
70+
'to' => array_map($addressStringifier, $email->getTo()),
7171
'subject' => $email->getSubject(),
7272
];
7373
if ($emails = array_map($addressStringifier, $email->getCc())) {
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Mailer\Bridge\Sendgrid\Tests\Http\Api;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Mailer\Bridge\Sendgrid\Http\Api\SendgridTransport;
16+
use Symfony\Component\Mime\Email;
17+
use Symfony\Contracts\HttpClient\HttpClientInterface;
18+
use Symfony\Contracts\HttpClient\ResponseInterface;
19+
20+
class SendgridTransportTest extends TestCase
21+
{
22+
public function testSend()
23+
{
24+
$email = new Email();
25+
$email->from('foo@example.com')
26+
->to('bar@example.com')
27+
->bcc('baz@example.com');
28+
29+
$response = $this->createMock(ResponseInterface::class);
30+
31+
$response
32+
->expects($this->once())
33+
->method('getStatusCode')
34+
->willReturn(202);
35+
36+
$httpClient = $this->createMock(HttpClientInterface::class);
37+
38+
$httpClient
39+
->expects($this->once())
40+
->method('request')
41+
->with('POST', 'https://api.sendgrid.com/v3/mail/send', [
42+
'json' => [
43+
'personalizations' => [
44+
[
45+
'to' => [['email' => 'bar@example.com']],
46+
'subject' => null,
47+
'bcc' => [['email' => 'baz@example.com']],
48+
],
49+
],
50+
'from' => ['email' => 'foo@example.com'],
51+
'content' => [],
52+
],
53+
'auth_bearer' => 'foo',
54+
])
55+
->willReturn($response);
56+
57+
$mailer = new SendgridTransport('foo', $httpClient);
58+
59+
$mailer->send($email);
60+
}
61+
}

SendgridTransportTest.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Mailer\Bridge\Sendgrid\Tests\Http\Api;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Mailer\Bridge\Sendgrid\Http\Api\SendgridTransport;
16+
use Symfony\Component\Mime\Email;
17+
use Symfony\Contracts\HttpClient\HttpClientInterface;
18+
use Symfony\Contracts\HttpClient\ResponseInterface;
19+
20+
class SendgridTransportTest extends TestCase
21+
{
22+
public function testSend()
23+
{
24+
$email = new Email();
25+
$email->from('foo@example.com')
26+
->to('bar@example.com')
27+
->bcc('baz@example.com');
28+
29+
$response = $this->createMock(ResponseInterface::class);
30+
31+
$response
32+
->expects($this->once())
33+
->method('getStatusCode')
34+
->willReturn(202);
35+
36+
$httpClient = $this->createMock(HttpClientInterface::class);
37+
38+
$httpClient
39+
->expects($this->once())
40+
->method('request')
41+
->with('POST', 'https://api.sendgrid.com/v3/mail/send', [
42+
'json' => [
43+
'personalizations' => [
44+
[
45+
'to' => [['email' => 'bar@example.com']],
46+
'subject' => null,
47+
'bcc' => [['email' => 'baz@example.com']],
48+
],
49+
],
50+
'from' => ['email' => 'foo@example.com'],
51+
'content' => [],
52+
],
53+
'auth_bearer' => 'foo',
54+
])
55+
->willReturn($response);
56+
57+
$mailer = new SendgridTransport('foo', $httpClient);
58+
59+
$mailer->send($email);
60+
}
61+
}

0 commit comments

Comments
 (0)