Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Mailer] Simplify the way TLS/SSL/STARTTLS work #33233

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ public function supportsProvider(): iterable
true,
];

yield [
new Dsn('smtps', 'ses'),
true,
];

yield [
new Dsn('smtp', 'example.com'),
false,
Expand Down Expand Up @@ -84,13 +89,18 @@ public function createProvider(): iterable
new Dsn('smtp', 'ses', self::USER, self::PASSWORD, null, ['region' => 'eu-west-1']),
new SesSmtpTransport(self::USER, self::PASSWORD, 'eu-west-1', $dispatcher, $logger),
];

yield [
new Dsn('smtps', 'ses', self::USER, self::PASSWORD, null, ['region' => 'eu-west-1']),
new SesSmtpTransport(self::USER, self::PASSWORD, 'eu-west-1', $dispatcher, $logger),
];
}

public function unsupportedSchemeProvider(): iterable
{
yield [
new Dsn('foo', 'ses', self::USER, self::PASSWORD),
'The "foo" scheme is not supported for mailer "ses". Supported schemes are: "api", "http", "smtp".',
'The "foo" scheme is not supported for mailer "ses". Supported schemes are: "api", "http", "smtp", "smtps".',
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class SesSmtpTransport extends EsmtpTransport
*/
public function __construct(string $username, string $password, string $region = null, EventDispatcherInterface $dispatcher = null, LoggerInterface $logger = null)
{
parent::__construct(sprintf('email-smtp.%s.amazonaws.com', $region ?: 'eu-west-1'), 587, 'tls', null, $dispatcher, $logger);
parent::__construct(sprintf('email-smtp.%s.amazonaws.com', $region ?: 'eu-west-1'), 587, true, null, $dispatcher, $logger);

$this->setUsername($username);
$this->setPassword($password);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ public function create(Dsn $dsn): TransportInterface
return new SesHttpTransport($user, $password, $region, $this->client, $this->dispatcher, $this->logger);
}

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

throw new UnsupportedSchemeException($dsn, ['api', 'http', 'smtp']);
throw new UnsupportedSchemeException($dsn, ['api', 'http', 'smtp', 'smtps']);
}

public function supports(Dsn $dsn): bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ public function supportsProvider(): iterable
true,
];

yield [
new Dsn('smtps', 'gmail'),
true,
];

yield [
new Dsn('smtp', 'example.com'),
false,
Expand All @@ -34,13 +39,18 @@ public function createProvider(): iterable
new Dsn('smtp', 'gmail', self::USER, self::PASSWORD),
new GmailSmtpTransport(self::USER, self::PASSWORD, $this->getDispatcher(), $this->getLogger()),
];

yield [
new Dsn('smtps', 'gmail', self::USER, self::PASSWORD),
new GmailSmtpTransport(self::USER, self::PASSWORD, $this->getDispatcher(), $this->getLogger()),
];
}

public function unsupportedSchemeProvider(): iterable
{
yield [
new Dsn('foo', 'gmail', self::USER, self::PASSWORD),
'The "foo" scheme is not supported for mailer "gmail". Supported schemes are: "smtp".',
'The "foo" scheme is not supported for mailer "gmail". Supported schemes are: "smtp", "smtps".',
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class GmailSmtpTransport extends EsmtpTransport
{
public function __construct(string $username, string $password, EventDispatcherInterface $dispatcher = null, LoggerInterface $logger = null)
{
parent::__construct('smtp.gmail.com', 465, 'ssl', null, $dispatcher, $logger);
parent::__construct('smtp.gmail.com', 465, true, null, $dispatcher, $logger);

$this->setUsername($username);
$this->setPassword($password);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ final class GmailTransportFactory extends AbstractTransportFactory
{
public function create(Dsn $dsn): TransportInterface
{
if ('smtp' === $dsn->getScheme()) {
if ('smtp' === $dsn->getScheme() || 'smtps' === $dsn->getScheme()) {
return new GmailSmtpTransport($this->getUser($dsn), $this->getPassword($dsn), $this->dispatcher, $this->logger);
}

throw new UnsupportedSchemeException($dsn, ['smtp']);
throw new UnsupportedSchemeException($dsn, ['smtp', 'smtps']);
}

public function supports(Dsn $dsn): bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ public function supportsProvider(): iterable
true,
];

yield [
new Dsn('smtps', 'mandrill'),
true,
];

yield [
new Dsn('smtp', 'example.com'),
false,
Expand All @@ -69,13 +74,18 @@ public function createProvider(): iterable
new Dsn('smtp', 'mandrill', self::USER, self::PASSWORD),
new MandrillSmtpTransport(self::USER, self::PASSWORD, $dispatcher, $logger),
];

yield [
new Dsn('smtps', 'mandrill', self::USER, self::PASSWORD),
new MandrillSmtpTransport(self::USER, self::PASSWORD, $dispatcher, $logger),
];
}

public function unsupportedSchemeProvider(): iterable
{
yield [
new Dsn('foo', 'mandrill', self::USER),
'The "foo" scheme is not supported for mailer "mandrill". Supported schemes are: "api", "http", "smtp".',
'The "foo" scheme is not supported for mailer "mandrill". Supported schemes are: "api", "http", "smtp", "smtps".',
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class MandrillSmtpTransport extends EsmtpTransport
{
public function __construct(string $username, string $password, EventDispatcherInterface $dispatcher = null, LoggerInterface $logger = null)
{
parent::__construct('smtp.mandrillapp.com', 587, 'tls', null, $dispatcher, $logger);
parent::__construct('smtp.mandrillapp.com', 587, true, null, $dispatcher, $logger);

$this->setUsername($username);
$this->setPassword($password);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ public function create(Dsn $dsn): TransportInterface
return new MandrillHttpTransport($user, $this->client, $this->dispatcher, $this->logger);
}

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

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

throw new UnsupportedSchemeException($dsn, ['api', 'http', 'smtp']);
throw new UnsupportedSchemeException($dsn, ['api', 'http', 'smtp', 'smtps']);
}

public function supports(Dsn $dsn): bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ public function supportsProvider(): iterable
true,
];

yield [
new Dsn('smtps', 'mailgun'),
true,
];

yield [
new Dsn('smtp', 'example.com'),
false,
Expand Down Expand Up @@ -74,13 +79,18 @@ public function createProvider(): iterable
new Dsn('smtp', 'mailgun', self::USER, self::PASSWORD),
new MailgunSmtpTransport(self::USER, self::PASSWORD, null, $dispatcher, $logger),
];

yield [
new Dsn('smtps', 'mailgun', self::USER, self::PASSWORD),
new MailgunSmtpTransport(self::USER, self::PASSWORD, null, $dispatcher, $logger),
];
}

public function unsupportedSchemeProvider(): iterable
{
yield [
new Dsn('foo', 'mailgun', self::USER, self::PASSWORD),
'The "foo" scheme is not supported for mailer "mailgun". Supported schemes are: "api", "http", "smtp".',
'The "foo" scheme is not supported for mailer "mailgun". Supported schemes are: "api", "http", "smtp", "smtps".',
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class MailgunSmtpTransport extends EsmtpTransport
{
public function __construct(string $username, string $password, string $region = null, EventDispatcherInterface $dispatcher = null, LoggerInterface $logger = null)
{
parent::__construct('us' !== ($region ?: 'us') ? sprintf('smtp.%s.mailgun.org', $region) : 'smtp.mailgun.org', 465, 'ssl', null, $dispatcher, $logger);
parent::__construct('us' !== ($region ?: 'us') ? sprintf('smtp.%s.mailgun.org', $region) : 'smtp.mailgun.org', 465, true, null, $dispatcher, $logger);

$this->setUsername($username);
$this->setPassword($password);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ public function create(Dsn $dsn): TransportInterface
return new MailgunHttpTransport($user, $password, $region, $this->client, $this->dispatcher, $this->logger);
}

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

throw new UnsupportedSchemeException($dsn, ['api', 'http', 'smtp']);
throw new UnsupportedSchemeException($dsn, ['api', 'http', 'smtp', 'smtps']);
}

public function supports(Dsn $dsn): bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ public function supportsProvider(): iterable
true,
];

yield [
new Dsn('smtps', 'postmark'),
true,
];

yield [
new Dsn('smtp', 'example.com'),
false,
Expand All @@ -57,13 +62,18 @@ public function createProvider(): iterable
new Dsn('smtp', 'postmark', self::USER),
new PostmarkSmtpTransport(self::USER, $dispatcher, $logger),
];

yield [
new Dsn('smtps', 'postmark', self::USER),
new PostmarkSmtpTransport(self::USER, $dispatcher, $logger),
];
}

public function unsupportedSchemeProvider(): iterable
{
yield [
new Dsn('foo', 'postmark', self::USER),
'The "foo" scheme is not supported for mailer "postmark". Supported schemes are: "api", "smtp".',
'The "foo" scheme is not supported for mailer "postmark". Supported schemes are: "api", "smtp", "smtps".',
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class PostmarkSmtpTransport extends EsmtpTransport
{
public function __construct(string $id, EventDispatcherInterface $dispatcher = null, LoggerInterface $logger = null)
{
parent::__construct('smtp.postmarkapp.com', 587, 'tls', null, $dispatcher, $logger);
parent::__construct('smtp.postmarkapp.com', 587, true, null, $dispatcher, $logger);

$this->setUsername($id);
$this->setPassword($id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ public function create(Dsn $dsn): TransportInterface
return new PostmarkApiTransport($user, $this->client, $this->dispatcher, $this->logger);
}

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

throw new UnsupportedSchemeException($dsn, ['api', 'smtp']);
throw new UnsupportedSchemeException($dsn, ['api', 'smtp', 'smtps']);
}

public function supports(Dsn $dsn): bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ public function supportsProvider(): iterable
true,
];

yield [
new Dsn('smtps', 'sendgrid'),
true,
];

yield [
new Dsn('smtp', 'example.com'),
false,
Expand All @@ -57,13 +62,18 @@ public function createProvider(): iterable
new Dsn('smtp', 'sendgrid', self::USER),
new SendgridSmtpTransport(self::USER, $dispatcher, $logger),
];

yield [
new Dsn('smtps', 'sendgrid', self::USER),
new SendgridSmtpTransport(self::USER, $dispatcher, $logger),
];
}

public function unsupportedSchemeProvider(): iterable
{
yield [
new Dsn('foo', 'sendgrid', self::USER),
'The "foo" scheme is not supported for mailer "sendgrid". Supported schemes are: "api", "smtp".',
'The "foo" scheme is not supported for mailer "sendgrid". Supported schemes are: "api", "smtp", "smtps".',
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class SendgridSmtpTransport extends EsmtpTransport
{
public function __construct(string $key, EventDispatcherInterface $dispatcher = null, LoggerInterface $logger = null)
{
parent::__construct('smtp.sendgrid.net', 465, 'ssl', null, $dispatcher, $logger);
parent::__construct('smtp.sendgrid.net', 465, true, null, $dispatcher, $logger);

$this->setUsername('apikey');
$this->setPassword($key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ public function create(Dsn $dsn): TransportInterface
return new SendgridApiTransport($key, $this->client, $this->dispatcher, $this->logger);
}

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

throw new UnsupportedSchemeException($dsn, ['api', 'smtp']);
throw new UnsupportedSchemeException($dsn, ['api', 'smtp', 'smtps']);
}

public function supports(Dsn $dsn): bool
Expand Down
3 changes: 3 additions & 0 deletions 3 src/Symfony/Component/Mailer/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ CHANGELOG
4.4.0
-----

* STARTTLS cannot be enabled anymore (it is used automatically if TLS is disabled and the server supports STARTTLS)
* [BC BREAK] Removed the `encryption` DSN option (use `smtps` instead)
* Added support for the `smtps` protocol (does the same as using `smtp` and port `465`)
* Added PHPUnit constraints
* Added `MessageDataCollector`
* Added `MessageEvents` and `MessageLoggerListener` to allow collecting sent emails
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function testCreate(Dsn $dsn, TransportInterface $transport): void
$factory = $this->getFactory();

$this->assertEquals($transport, $factory->create($dsn));
if ('smtp' !== $dsn->getScheme()) {
if ('smtp' !== $dsn->getScheme() && 'smtps' !== $dsn->getScheme()) {
$this->assertStringMatchesFormat($dsn->getScheme().'://%S'.$dsn->getHost().'%S', $transport->getName());
}
}
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.