Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1042a3c

Browse files
committed
[Mailer] simplified the way TLS/SSL/StartTls work
1 parent bc79cfe commit 1042a3c

28 files changed

+189
-63
lines changed

src/Symfony/Component/Mailer/Bridge/Amazon/Tests/Transport/SesTransportFactoryTest.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ public function supportsProvider(): iterable
4343
true,
4444
];
4545

46+
yield [
47+
new Dsn('smtps', 'ses'),
48+
true,
49+
];
50+
4651
yield [
4752
new Dsn('smtp', 'example.com'),
4853
false,
@@ -84,13 +89,18 @@ public function createProvider(): iterable
8489
new Dsn('smtp', 'ses', self::USER, self::PASSWORD, null, ['region' => 'eu-west-1']),
8590
new SesSmtpTransport(self::USER, self::PASSWORD, 'eu-west-1', $dispatcher, $logger),
8691
];
92+
93+
yield [
94+
new Dsn('smtps', 'ses', self::USER, self::PASSWORD, null, ['region' => 'eu-west-1']),
95+
new SesSmtpTransport(self::USER, self::PASSWORD, 'eu-west-1', $dispatcher, $logger),
96+
];
8797
}
8898

8999
public function unsupportedSchemeProvider(): iterable
90100
{
91101
yield [
92102
new Dsn('foo', 'ses', self::USER, self::PASSWORD),
93-
'The "foo" scheme is not supported for mailer "ses". Supported schemes are: "api", "http", "smtp".',
103+
'The "foo" scheme is not supported for mailer "ses". Supported schemes are: "api", "http", "smtp", "smtps".',
94104
];
95105
}
96106

src/Symfony/Component/Mailer/Bridge/Amazon/Transport/SesSmtpTransport.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class SesSmtpTransport extends EsmtpTransport
2525
*/
2626
public function __construct(string $username, string $password, string $region = null, EventDispatcherInterface $dispatcher = null, LoggerInterface $logger = null)
2727
{
28-
parent::__construct(sprintf('email-smtp.%s.amazonaws.com', $region ?: 'eu-west-1'), 587, 'tls', null, $dispatcher, $logger);
28+
parent::__construct(sprintf('email-smtp.%s.amazonaws.com', $region ?: 'eu-west-1'), 587, true, null, $dispatcher, $logger);
2929

3030
$this->setUsername($username);
3131
$this->setPassword($password);

src/Symfony/Component/Mailer/Bridge/Amazon/Transport/SesTransportFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ public function create(Dsn $dsn): TransportInterface
3636
return new SesHttpTransport($user, $password, $region, $this->client, $this->dispatcher, $this->logger);
3737
}
3838

39-
if ('smtp' === $scheme) {
39+
if ('smtp' === $scheme || 'smtps' === $scheme) {
4040
return new SesSmtpTransport($user, $password, $region, $this->dispatcher, $this->logger);
4141
}
4242

43-
throw new UnsupportedSchemeException($dsn, ['api', 'http', 'smtp']);
43+
throw new UnsupportedSchemeException($dsn, ['api', 'http', 'smtp', 'smtps']);
4444
}
4545

4646
public function supports(Dsn $dsn): bool

src/Symfony/Component/Mailer/Bridge/Google/Tests/Transport/GmailTransportFactoryTest.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ public function supportsProvider(): iterable
2222
true,
2323
];
2424

25+
yield [
26+
new Dsn('smtps', 'gmail'),
27+
true,
28+
];
29+
2530
yield [
2631
new Dsn('smtp', 'example.com'),
2732
false,
@@ -34,13 +39,18 @@ public function createProvider(): iterable
3439
new Dsn('smtp', 'gmail', self::USER, self::PASSWORD),
3540
new GmailSmtpTransport(self::USER, self::PASSWORD, $this->getDispatcher(), $this->getLogger()),
3641
];
42+
43+
yield [
44+
new Dsn('smtps', 'gmail', self::USER, self::PASSWORD),
45+
new GmailSmtpTransport(self::USER, self::PASSWORD, $this->getDispatcher(), $this->getLogger()),
46+
];
3747
}
3848

3949
public function unsupportedSchemeProvider(): iterable
4050
{
4151
yield [
4252
new Dsn('foo', 'gmail', self::USER, self::PASSWORD),
43-
'The "foo" scheme is not supported for mailer "gmail". Supported schemes are: "smtp".',
53+
'The "foo" scheme is not supported for mailer "gmail". Supported schemes are: "smtp", "smtps".',
4454
];
4555
}
4656

src/Symfony/Component/Mailer/Bridge/Google/Transport/GmailSmtpTransport.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class GmailSmtpTransport extends EsmtpTransport
2222
{
2323
public function __construct(string $username, string $password, EventDispatcherInterface $dispatcher = null, LoggerInterface $logger = null)
2424
{
25-
parent::__construct('smtp.gmail.com', 465, 'ssl', null, $dispatcher, $logger);
25+
parent::__construct('smtp.gmail.com', 465, true, null, $dispatcher, $logger);
2626

2727
$this->setUsername($username);
2828
$this->setPassword($password);

src/Symfony/Component/Mailer/Bridge/Google/Transport/GmailTransportFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ final class GmailTransportFactory extends AbstractTransportFactory
2323
{
2424
public function create(Dsn $dsn): TransportInterface
2525
{
26-
if ('smtp' === $dsn->getScheme()) {
26+
if ('smtp' === $dsn->getScheme() || 'smtps' === $dsn->getScheme()) {
2727
return new GmailSmtpTransport($this->getUser($dsn), $this->getPassword($dsn), $this->dispatcher, $this->logger);
2828
}
2929

30-
throw new UnsupportedSchemeException($dsn, ['smtp']);
30+
throw new UnsupportedSchemeException($dsn, ['smtp', 'smtps']);
3131
}
3232

3333
public function supports(Dsn $dsn): bool

src/Symfony/Component/Mailer/Bridge/Mailchimp/Tests/Transport/MandrillTransportFactoryTest.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ public function supportsProvider(): iterable
4343
true,
4444
];
4545

46+
yield [
47+
new Dsn('smtps', 'mandrill'),
48+
true,
49+
];
50+
4651
yield [
4752
new Dsn('smtp', 'example.com'),
4853
false,
@@ -69,13 +74,18 @@ public function createProvider(): iterable
6974
new Dsn('smtp', 'mandrill', self::USER, self::PASSWORD),
7075
new MandrillSmtpTransport(self::USER, self::PASSWORD, $dispatcher, $logger),
7176
];
77+
78+
yield [
79+
new Dsn('smtps', 'mandrill', self::USER, self::PASSWORD),
80+
new MandrillSmtpTransport(self::USER, self::PASSWORD, $dispatcher, $logger),
81+
];
7282
}
7383

7484
public function unsupportedSchemeProvider(): iterable
7585
{
7686
yield [
7787
new Dsn('foo', 'mandrill', self::USER),
78-
'The "foo" scheme is not supported for mailer "mandrill". Supported schemes are: "api", "http", "smtp".',
88+
'The "foo" scheme is not supported for mailer "mandrill". Supported schemes are: "api", "http", "smtp", "smtps".',
7989
];
8090
}
8191

src/Symfony/Component/Mailer/Bridge/Mailchimp/Transport/MandrillSmtpTransport.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class MandrillSmtpTransport extends EsmtpTransport
2222
{
2323
public function __construct(string $username, string $password, EventDispatcherInterface $dispatcher = null, LoggerInterface $logger = null)
2424
{
25-
parent::__construct('smtp.mandrillapp.com', 587, 'tls', null, $dispatcher, $logger);
25+
parent::__construct('smtp.mandrillapp.com', 587, true, null, $dispatcher, $logger);
2626

2727
$this->setUsername($username);
2828
$this->setPassword($password);

src/Symfony/Component/Mailer/Bridge/Mailchimp/Transport/MandrillTransportFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ public function create(Dsn $dsn): TransportInterface
3434
return new MandrillHttpTransport($user, $this->client, $this->dispatcher, $this->logger);
3535
}
3636

37-
if ('smtp' === $scheme) {
37+
if ('smtp' === $scheme || 'smtps' === $scheme) {
3838
$password = $this->getPassword($dsn);
3939

4040
return new MandrillSmtpTransport($user, $password, $this->dispatcher, $this->logger);
4141
}
4242

43-
throw new UnsupportedSchemeException($dsn, ['api', 'http', 'smtp']);
43+
throw new UnsupportedSchemeException($dsn, ['api', 'http', 'smtp', 'smtps']);
4444
}
4545

4646
public function supports(Dsn $dsn): bool

src/Symfony/Component/Mailer/Bridge/Mailgun/Tests/Transport/MailgunTransportFactoryTest.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ public function supportsProvider(): iterable
4343
true,
4444
];
4545

46+
yield [
47+
new Dsn('smtps', 'mailgun'),
48+
true,
49+
];
50+
4651
yield [
4752
new Dsn('smtp', 'example.com'),
4853
false,
@@ -74,13 +79,18 @@ public function createProvider(): iterable
7479
new Dsn('smtp', 'mailgun', self::USER, self::PASSWORD),
7580
new MailgunSmtpTransport(self::USER, self::PASSWORD, null, $dispatcher, $logger),
7681
];
82+
83+
yield [
84+
new Dsn('smtps', 'mailgun', self::USER, self::PASSWORD),
85+
new MailgunSmtpTransport(self::USER, self::PASSWORD, null, $dispatcher, $logger),
86+
];
7787
}
7888

7989
public function unsupportedSchemeProvider(): iterable
8090
{
8191
yield [
8292
new Dsn('foo', 'mailgun', self::USER, self::PASSWORD),
83-
'The "foo" scheme is not supported for mailer "mailgun". Supported schemes are: "api", "http", "smtp".',
93+
'The "foo" scheme is not supported for mailer "mailgun". Supported schemes are: "api", "http", "smtp", "smtps".',
8494
];
8595
}
8696

src/Symfony/Component/Mailer/Bridge/Mailgun/Transport/MailgunSmtpTransport.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class MailgunSmtpTransport extends EsmtpTransport
2222
{
2323
public function __construct(string $username, string $password, string $region = null, EventDispatcherInterface $dispatcher = null, LoggerInterface $logger = null)
2424
{
25-
parent::__construct('us' !== ($region ?: 'us') ? sprintf('smtp.%s.mailgun.org', $region) : 'smtp.mailgun.org', 465, 'ssl', null, $dispatcher, $logger);
25+
parent::__construct('us' !== ($region ?: 'us') ? sprintf('smtp.%s.mailgun.org', $region) : 'smtp.mailgun.org', 465, true, null, $dispatcher, $logger);
2626

2727
$this->setUsername($username);
2828
$this->setPassword($password);

src/Symfony/Component/Mailer/Bridge/Mailgun/Transport/MailgunTransportFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ public function create(Dsn $dsn): TransportInterface
3636
return new MailgunHttpTransport($user, $password, $region, $this->client, $this->dispatcher, $this->logger);
3737
}
3838

39-
if ('smtp' === $scheme) {
39+
if ('smtp' === $scheme || 'smtps' === $scheme) {
4040
return new MailgunSmtpTransport($user, $password, $region, $this->dispatcher, $this->logger);
4141
}
4242

43-
throw new UnsupportedSchemeException($dsn, ['api', 'http', 'smtp']);
43+
throw new UnsupportedSchemeException($dsn, ['api', 'http', 'smtp', 'smtps']);
4444
}
4545

4646
public function supports(Dsn $dsn): bool

src/Symfony/Component/Mailer/Bridge/Postmark/Tests/Transport/PostmarkTransportFactoryTest.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ public function supportsProvider(): iterable
3737
true,
3838
];
3939

40+
yield [
41+
new Dsn('smtps', 'postmark'),
42+
true,
43+
];
44+
4045
yield [
4146
new Dsn('smtp', 'example.com'),
4247
false,
@@ -57,13 +62,18 @@ public function createProvider(): iterable
5762
new Dsn('smtp', 'postmark', self::USER),
5863
new PostmarkSmtpTransport(self::USER, $dispatcher, $logger),
5964
];
65+
66+
yield [
67+
new Dsn('smtps', 'postmark', self::USER),
68+
new PostmarkSmtpTransport(self::USER, $dispatcher, $logger),
69+
];
6070
}
6171

6272
public function unsupportedSchemeProvider(): iterable
6373
{
6474
yield [
6575
new Dsn('foo', 'postmark', self::USER),
66-
'The "foo" scheme is not supported for mailer "postmark". Supported schemes are: "api", "smtp".',
76+
'The "foo" scheme is not supported for mailer "postmark". Supported schemes are: "api", "smtp", "smtps".',
6777
];
6878
}
6979

src/Symfony/Component/Mailer/Bridge/Postmark/Transport/PostmarkSmtpTransport.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class PostmarkSmtpTransport extends EsmtpTransport
2222
{
2323
public function __construct(string $id, EventDispatcherInterface $dispatcher = null, LoggerInterface $logger = null)
2424
{
25-
parent::__construct('smtp.postmarkapp.com', 587, 'tls', null, $dispatcher, $logger);
25+
parent::__construct('smtp.postmarkapp.com', 587, true, null, $dispatcher, $logger);
2626

2727
$this->setUsername($id);
2828
$this->setPassword($id);

src/Symfony/Component/Mailer/Bridge/Postmark/Transport/PostmarkTransportFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ public function create(Dsn $dsn): TransportInterface
3030
return new PostmarkApiTransport($user, $this->client, $this->dispatcher, $this->logger);
3131
}
3232

33-
if ('smtp' === $scheme) {
33+
if ('smtp' === $scheme || 'smtps' === $scheme) {
3434
return new PostmarkSmtpTransport($user, $this->dispatcher, $this->logger);
3535
}
3636

37-
throw new UnsupportedSchemeException($dsn, ['api', 'smtp']);
37+
throw new UnsupportedSchemeException($dsn, ['api', 'smtp', 'smtps']);
3838
}
3939

4040
public function supports(Dsn $dsn): bool

src/Symfony/Component/Mailer/Bridge/Sendgrid/Tests/Transport/SendgridTransportFactoryTest.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ public function supportsProvider(): iterable
3737
true,
3838
];
3939

40+
yield [
41+
new Dsn('smtps', 'sendgrid'),
42+
true,
43+
];
44+
4045
yield [
4146
new Dsn('smtp', 'example.com'),
4247
false,
@@ -57,13 +62,18 @@ public function createProvider(): iterable
5762
new Dsn('smtp', 'sendgrid', self::USER),
5863
new SendgridSmtpTransport(self::USER, $dispatcher, $logger),
5964
];
65+
66+
yield [
67+
new Dsn('smtps', 'sendgrid', self::USER),
68+
new SendgridSmtpTransport(self::USER, $dispatcher, $logger),
69+
];
6070
}
6171

6272
public function unsupportedSchemeProvider(): iterable
6373
{
6474
yield [
6575
new Dsn('foo', 'sendgrid', self::USER),
66-
'The "foo" scheme is not supported for mailer "sendgrid". Supported schemes are: "api", "smtp".',
76+
'The "foo" scheme is not supported for mailer "sendgrid". Supported schemes are: "api", "smtp", "smtps".',
6777
];
6878
}
6979
}

src/Symfony/Component/Mailer/Bridge/Sendgrid/Transport/SendgridSmtpTransport.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class SendgridSmtpTransport extends EsmtpTransport
2222
{
2323
public function __construct(string $key, EventDispatcherInterface $dispatcher = null, LoggerInterface $logger = null)
2424
{
25-
parent::__construct('smtp.sendgrid.net', 465, 'ssl', null, $dispatcher, $logger);
25+
parent::__construct('smtp.sendgrid.net', 465, true, null, $dispatcher, $logger);
2626

2727
$this->setUsername('apikey');
2828
$this->setPassword($key);

src/Symfony/Component/Mailer/Bridge/Sendgrid/Transport/SendgridTransportFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ public function create(Dsn $dsn): TransportInterface
2929
return new SendgridApiTransport($key, $this->client, $this->dispatcher, $this->logger);
3030
}
3131

32-
if ('smtp' === $dsn->getScheme()) {
32+
if ('smtp' === $dsn->getScheme() || 'smtps' === $dsn->getScheme()) {
3333
return new SendgridSmtpTransport($key, $this->dispatcher, $this->logger);
3434
}
3535

36-
throw new UnsupportedSchemeException($dsn, ['api', 'smtp']);
36+
throw new UnsupportedSchemeException($dsn, ['api', 'smtp', 'smtps']);
3737
}
3838

3939
public function supports(Dsn $dsn): bool

src/Symfony/Component/Mailer/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ CHANGELOG
44
4.4.0
55
-----
66

7+
* STARTTLS cannot be enabled anymore (it is used automatically if TLS is disabled and the server supports STARTTLS)
8+
* [BC BREAK] Removed the `encryption` DSN option (use `smtps` instead)
9+
* Added support for the `smtps` protocol (does the same as using `smtp` and port `465`)
710
* Added PHPUnit constraints
811
* Added `MessageDataCollector`
912
* Added `MessageEvents` and `MessageLoggerListener` to allow collecting sent emails

src/Symfony/Component/Mailer/Test/TransportFactoryTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function testCreate(Dsn $dsn, TransportInterface $transport): void
6969
$factory = $this->getFactory();
7070

7171
$this->assertEquals($transport, $factory->create($dsn));
72-
if ('smtp' !== $dsn->getScheme()) {
72+
if ('smtp' !== $dsn->getScheme() && 'smtps' !== $dsn->getScheme()) {
7373
$this->assertStringMatchesFormat($dsn->getScheme().'://%S'.$dsn->getHost().'%S', $transport->getName());
7474
}
7575
}

0 commit comments

Comments
 (0)