Loading core/lib/Drupal/Core/Mail/Plugin/Mail/SymfonyMailer.php +13 −4 Original line number Diff line number Diff line Loading @@ -12,6 +12,7 @@ use Symfony\Component\Mailer\Mailer; use Symfony\Component\Mailer\MailerInterface; use Symfony\Component\Mailer\Transport; use Symfony\Component\Mailer\Transport\Dsn; use Symfony\Component\Mime\Email; /** Loading @@ -35,11 +36,16 @@ * * @code * $config['system.mail']['interface'] = [ 'default' => 'symfony_mailer' ]; * $config['system.mail']['mailer_dsn'] = 'smtp://user:pass@smtp.example.com:25'; * $config['system.mail']['mailer_dsn'] = [ * 'scheme' => 'smtp', * 'host' => 'smtp.example.com', * 'port' => 25, * 'user' => 'user', * 'password' => 'pass', * 'options' => [], * ]; * @endcode * * Note that special characters in the mailer_dsn need to be URL encoded. * * @see https://symfony.com/doc/current/mailer.html#using-built-in-transports * * @Mail( Loading Loading @@ -143,6 +149,7 @@ public function mail(array $message) { protected function getMailer(): MailerInterface { if (!isset($this->mailer)) { $dsn = \Drupal::config('system.mail')->get('mailer_dsn'); $dsnObject = new Dsn(...$dsn); // Symfony Mailer and Transport classes both optionally depend on the // event dispatcher. When provided, a MessageEvent is fired whenever an Loading @@ -154,7 +161,9 @@ protected function getMailer(): MailerInterface { // mails into the code path (i.e., event subscribers) of the new API. // Therefore, this plugin deliberately refrains from injecting the event // dispatcher. $transport = Transport::fromDsn($dsn, logger: $this->logger); $factories = Transport::getDefaultFactories(logger: $this->logger); $transportFactory = new Transport($factories); $transport = $transportFactory->fromDsnObject($dsnObject); $this->mailer = new Mailer($transport); } Loading core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php +8 −1 Original line number Diff line number Diff line Loading @@ -330,7 +330,14 @@ protected function initConfig(ContainerInterface $container) { // some tests expect to be able to test mail system implementations. $config->getEditable('system.mail') ->set('interface.default', 'test_mail_collector') ->set('mailer_dsn', 'null://null') ->set('mailer_dsn', [ 'scheme' => 'null', 'host' => 'null', 'user' => NULL, 'password' => NULL, 'port' => NULL, 'options' => [], ]) ->save(); // By default, verbosely display all errors and disable all production Loading core/modules/migrate_drupal_ui/tests/src/Functional/MigrateUpgradeExecuteTestBase.php +6 −2 Original line number Diff line number Diff line Loading @@ -65,8 +65,12 @@ public function useTestMailCollector() { 'value' => 'test_mail_collector', 'required' => TRUE, ]; $settings['config']['system.mail']['mailer_dsn'] = (object) [ 'value' => 'null://null', $settings['config']['system.mail']['mailer_dsn']['scheme'] = (object) [ 'value' => 'null', 'required' => TRUE, ]; $settings['config']['system.mail']['mailer_dsn']['host'] = (object) [ 'value' => 'null', 'required' => TRUE, ]; $this->writeSettings($settings); Loading core/modules/system/config/install/system.mail.yml +7 −1 Original line number Diff line number Diff line interface: default: 'php_mail' mailer_dsn: "sendmail://default" mailer_dsn: scheme: 'sendmail' host: 'default' user: null password: null port: null options: [] core/modules/system/config/schema/system.schema.yml +38 −1 Original line number Diff line number Diff line Loading @@ -304,8 +304,45 @@ system.mail: type: string label: 'Interface' mailer_dsn: type: string type: mapping label: 'Symfony mailer transport DSN' mapping: scheme: type: string label: 'Scheme' constraints: NotBlank: message: 'The mailer DSN must contain a scheme.' host: type: string label: 'Host' constraints: NotBlank: message: 'The mailer DSN must contain a host (use "default" by default).' user: type: string nullable: true label: 'User' password: type: string nullable: true label: 'Password' port: type: integer nullable: true label: 'Port' constraints: Range: min: 0 max: 65535 options: type: sequence label: 'Options' sequence: type: string label: Option constraints: NotNull: [] system.theme.global: type: theme_settings Loading Loading
core/lib/Drupal/Core/Mail/Plugin/Mail/SymfonyMailer.php +13 −4 Original line number Diff line number Diff line Loading @@ -12,6 +12,7 @@ use Symfony\Component\Mailer\Mailer; use Symfony\Component\Mailer\MailerInterface; use Symfony\Component\Mailer\Transport; use Symfony\Component\Mailer\Transport\Dsn; use Symfony\Component\Mime\Email; /** Loading @@ -35,11 +36,16 @@ * * @code * $config['system.mail']['interface'] = [ 'default' => 'symfony_mailer' ]; * $config['system.mail']['mailer_dsn'] = 'smtp://user:pass@smtp.example.com:25'; * $config['system.mail']['mailer_dsn'] = [ * 'scheme' => 'smtp', * 'host' => 'smtp.example.com', * 'port' => 25, * 'user' => 'user', * 'password' => 'pass', * 'options' => [], * ]; * @endcode * * Note that special characters in the mailer_dsn need to be URL encoded. * * @see https://symfony.com/doc/current/mailer.html#using-built-in-transports * * @Mail( Loading Loading @@ -143,6 +149,7 @@ public function mail(array $message) { protected function getMailer(): MailerInterface { if (!isset($this->mailer)) { $dsn = \Drupal::config('system.mail')->get('mailer_dsn'); $dsnObject = new Dsn(...$dsn); // Symfony Mailer and Transport classes both optionally depend on the // event dispatcher. When provided, a MessageEvent is fired whenever an Loading @@ -154,7 +161,9 @@ protected function getMailer(): MailerInterface { // mails into the code path (i.e., event subscribers) of the new API. // Therefore, this plugin deliberately refrains from injecting the event // dispatcher. $transport = Transport::fromDsn($dsn, logger: $this->logger); $factories = Transport::getDefaultFactories(logger: $this->logger); $transportFactory = new Transport($factories); $transport = $transportFactory->fromDsnObject($dsnObject); $this->mailer = new Mailer($transport); } Loading
core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php +8 −1 Original line number Diff line number Diff line Loading @@ -330,7 +330,14 @@ protected function initConfig(ContainerInterface $container) { // some tests expect to be able to test mail system implementations. $config->getEditable('system.mail') ->set('interface.default', 'test_mail_collector') ->set('mailer_dsn', 'null://null') ->set('mailer_dsn', [ 'scheme' => 'null', 'host' => 'null', 'user' => NULL, 'password' => NULL, 'port' => NULL, 'options' => [], ]) ->save(); // By default, verbosely display all errors and disable all production Loading
core/modules/migrate_drupal_ui/tests/src/Functional/MigrateUpgradeExecuteTestBase.php +6 −2 Original line number Diff line number Diff line Loading @@ -65,8 +65,12 @@ public function useTestMailCollector() { 'value' => 'test_mail_collector', 'required' => TRUE, ]; $settings['config']['system.mail']['mailer_dsn'] = (object) [ 'value' => 'null://null', $settings['config']['system.mail']['mailer_dsn']['scheme'] = (object) [ 'value' => 'null', 'required' => TRUE, ]; $settings['config']['system.mail']['mailer_dsn']['host'] = (object) [ 'value' => 'null', 'required' => TRUE, ]; $this->writeSettings($settings); Loading
core/modules/system/config/install/system.mail.yml +7 −1 Original line number Diff line number Diff line interface: default: 'php_mail' mailer_dsn: "sendmail://default" mailer_dsn: scheme: 'sendmail' host: 'default' user: null password: null port: null options: []
core/modules/system/config/schema/system.schema.yml +38 −1 Original line number Diff line number Diff line Loading @@ -304,8 +304,45 @@ system.mail: type: string label: 'Interface' mailer_dsn: type: string type: mapping label: 'Symfony mailer transport DSN' mapping: scheme: type: string label: 'Scheme' constraints: NotBlank: message: 'The mailer DSN must contain a scheme.' host: type: string label: 'Host' constraints: NotBlank: message: 'The mailer DSN must contain a host (use "default" by default).' user: type: string nullable: true label: 'User' password: type: string nullable: true label: 'Password' port: type: integer nullable: true label: 'Port' constraints: Range: min: 0 max: 65535 options: type: sequence label: 'Options' sequence: type: string label: Option constraints: NotNull: [] system.theme.global: type: theme_settings Loading