feature #33237 [Mailer] Remove the auth mode DSN option and support in the eSMTP transport (fabpot)
This PR was merged into the 4.4 branch.
Discussion
----------
[Mailer] Remove the auth mode DSN option and support in the eSMTP transport
| Q | A
| ------------- | ---
| Branch? | 4.4
| Bug fix? | no
| New feature? | yes
| BC breaks? | yes <!-- see https://symfony.com/bc -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass? | yes <!-- please add some, will be required by reviewers -->
| Fixed tickets | n/a
| License | MIT
| Doc PR | -
The authentication mode can be automatically negotiated between the Mailer and the SMTP server. There is an option to force it to a given auth mode, but I don't see any valid use case. So, let's remove that feature.
Commits
-------
34cbda53c4
[Mailer] removed the auth mode DSN option and support in the eSMTP transport
This commit is contained in:
commit
ce372672d0
@ -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, true, null, $dispatcher, $logger);
|
||||
parent::__construct(sprintf('email-smtp.%s.amazonaws.com', $region ?: 'eu-west-1'), 587, true, $dispatcher, $logger);
|
||||
|
||||
$this->setUsername($username);
|
||||
$this->setPassword($password);
|
||||
|
@ -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, true, null, $dispatcher, $logger);
|
||||
parent::__construct('smtp.gmail.com', 465, true, $dispatcher, $logger);
|
||||
|
||||
$this->setUsername($username);
|
||||
$this->setPassword($password);
|
||||
|
@ -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, true, null, $dispatcher, $logger);
|
||||
parent::__construct('smtp.mandrillapp.com', 587, true, $dispatcher, $logger);
|
||||
|
||||
$this->setUsername($username);
|
||||
$this->setPassword($password);
|
||||
|
@ -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, true, null, $dispatcher, $logger);
|
||||
parent::__construct('us' !== ($region ?: 'us') ? sprintf('smtp.%s.mailgun.org', $region) : 'smtp.mailgun.org', 465, true, $dispatcher, $logger);
|
||||
|
||||
$this->setUsername($username);
|
||||
$this->setPassword($password);
|
||||
|
@ -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, true, null, $dispatcher, $logger);
|
||||
parent::__construct('smtp.postmarkapp.com', 587, true, $dispatcher, $logger);
|
||||
|
||||
$this->setUsername($id);
|
||||
$this->setPassword($id);
|
||||
|
@ -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, true, null, $dispatcher, $logger);
|
||||
parent::__construct('smtp.sendgrid.net', 465, true, $dispatcher, $logger);
|
||||
|
||||
$this->setUsername('apikey');
|
||||
$this->setPassword($key);
|
||||
|
@ -4,6 +4,7 @@ CHANGELOG
|
||||
4.4.0
|
||||
-----
|
||||
|
||||
* [BC BREAK] removed the `auth_mode` DSN option (it is now always determined automatically)
|
||||
* 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`)
|
||||
|
@ -38,30 +38,30 @@ class EsmtpTransportFactoryTest extends TransportFactoryTestCase
|
||||
$eventDispatcher = $this->getDispatcher();
|
||||
$logger = $this->getLogger();
|
||||
|
||||
$transport = new EsmtpTransport('localhost', 25, false, null, $eventDispatcher, $logger);
|
||||
$transport = new EsmtpTransport('localhost', 25, false, $eventDispatcher, $logger);
|
||||
|
||||
yield [
|
||||
new Dsn('smtp', 'localhost'),
|
||||
$transport,
|
||||
];
|
||||
|
||||
$transport = new EsmtpTransport('example.com', 99, true, 'login', $eventDispatcher, $logger);
|
||||
$transport = new EsmtpTransport('example.com', 99, true, $eventDispatcher, $logger);
|
||||
$transport->setUsername(self::USER);
|
||||
$transport->setPassword(self::PASSWORD);
|
||||
|
||||
yield [
|
||||
new Dsn('smtps', 'example.com', self::USER, self::PASSWORD, 99, ['auth_mode' => 'login']),
|
||||
new Dsn('smtps', 'example.com', self::USER, self::PASSWORD, 99),
|
||||
$transport,
|
||||
];
|
||||
|
||||
$transport = new EsmtpTransport('example.com', 465, true, null, $eventDispatcher, $logger);
|
||||
$transport = new EsmtpTransport('example.com', 465, true, $eventDispatcher, $logger);
|
||||
|
||||
yield [
|
||||
new Dsn('smtps', 'example.com'),
|
||||
$transport,
|
||||
];
|
||||
|
||||
$transport = new EsmtpTransport('example.com', 465, true, null, $eventDispatcher, $logger);
|
||||
$transport = new EsmtpTransport('example.com', 465, true, $eventDispatcher, $logger);
|
||||
|
||||
yield [
|
||||
new Dsn('smtp', 'example.com', '', '', 465),
|
||||
|
@ -29,12 +29,12 @@ class EsmtpTransport extends SmtpTransport
|
||||
private $authenticators = [];
|
||||
private $username = '';
|
||||
private $password = '';
|
||||
private $authMode;
|
||||
|
||||
public function __construct(string $host = 'localhost', int $port = 0, bool $tls = null, string $authMode = null, EventDispatcherInterface $dispatcher = null, LoggerInterface $logger = null)
|
||||
public function __construct(string $host = 'localhost', int $port = 0, bool $tls = null, EventDispatcherInterface $dispatcher = null, LoggerInterface $logger = null)
|
||||
{
|
||||
parent::__construct(null, $dispatcher, $logger);
|
||||
|
||||
// order is important here (roughly most secure and popular first)
|
||||
$this->authenticators = [
|
||||
new Auth\CramMd5Authenticator(),
|
||||
new Auth\LoginAuthenticator(),
|
||||
@ -61,9 +61,6 @@ class EsmtpTransport extends SmtpTransport
|
||||
|
||||
$stream->setHost($host);
|
||||
$stream->setPort($port);
|
||||
if (null !== $authMode) {
|
||||
$this->setAuthMode($authMode);
|
||||
}
|
||||
}
|
||||
|
||||
public function setUsername(string $username): self
|
||||
@ -90,18 +87,6 @@ class EsmtpTransport extends SmtpTransport
|
||||
return $this->password;
|
||||
}
|
||||
|
||||
public function setAuthMode(string $mode): self
|
||||
{
|
||||
$this->authMode = $mode;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getAuthMode(): string
|
||||
{
|
||||
return $this->authMode;
|
||||
}
|
||||
|
||||
public function addAuthenticator(AuthenticatorInterface $authenticator): void
|
||||
{
|
||||
$this->authenticators[] = $authenticator;
|
||||
@ -166,7 +151,7 @@ class EsmtpTransport extends SmtpTransport
|
||||
$authNames = [];
|
||||
$errors = [];
|
||||
$modes = array_map('strtolower', $modes);
|
||||
foreach ($this->getActiveAuthenticators() as $authenticator) {
|
||||
foreach ($this->authenticators as $authenticator) {
|
||||
if (!\in_array(strtolower($authenticator->getAuthKeyword()), $modes, true)) {
|
||||
continue;
|
||||
}
|
||||
@ -195,22 +180,4 @@ class EsmtpTransport extends SmtpTransport
|
||||
|
||||
throw new TransportException($message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return AuthenticatorInterface[]
|
||||
*/
|
||||
private function getActiveAuthenticators(): array
|
||||
{
|
||||
if (!$mode = strtolower($this->authMode)) {
|
||||
return $this->authenticators;
|
||||
}
|
||||
|
||||
foreach ($this->authenticators as $authenticator) {
|
||||
if (strtolower($authenticator->getAuthKeyword()) === $mode) {
|
||||
return [$authenticator];
|
||||
}
|
||||
}
|
||||
|
||||
throw new TransportException(sprintf('Auth mode "%s" is invalid.', $mode));
|
||||
}
|
||||
}
|
||||
|
@ -23,11 +23,10 @@ final class EsmtpTransportFactory extends AbstractTransportFactory
|
||||
public function create(Dsn $dsn): TransportInterface
|
||||
{
|
||||
$tls = 'smtps' === $dsn->getScheme() ? true : null;
|
||||
$authMode = $dsn->getOption('auth_mode');
|
||||
$port = $dsn->getPort(0);
|
||||
$host = $dsn->getHost();
|
||||
|
||||
$transport = new EsmtpTransport($host, $port, $tls, $authMode, $this->dispatcher, $this->logger);
|
||||
$transport = new EsmtpTransport($host, $port, $tls, $this->dispatcher, $this->logger);
|
||||
|
||||
if ($user = $dsn->getUser()) {
|
||||
$transport->setUsername($user);
|
||||
|
Reference in New Issue
Block a user