Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 299379

Add symfony/mailer into core

$
0
0

Problem/Motivation

Drupal core mail capabilities are stuck in the early 2000.

Steps to reproduce

Attempt to use mailhog (in development) or SMTP (in production).

Proposed resolution

As per symfony docs:

Symfony's Mailer & Mime components form a powerful system for creating and sending emails - complete with support for multipart messages, Twig integration, CSS inlining, file attachments and a lot more. Get them installed with:

Emails are delivered via a "transport". Out of the box, you can deliver emails over SMTP. Instead of using your own SMTP server or sendmail binary, you can send emails via a third-party provider.

Symfony mailer is maintained in the symfony framework repository. Like all symfony components it is available as a separate package as well.

As a pre-requisite of #1803948: [META] Adopt the symfony mailer component, add the symfony/mailer component as a composer dependency to Drupal core. Additionally make all supported symfony mailer transports accessible via a simple mail plugin which can act as a drop-in replacement for the existing php mail plugin.

Behavioral changes compared to PHP mailer plugin

The Symfony mime component doesn't support format=flowed soft wrapped text. Thus, mails sent with the Symfony mailer plugin may look slightly different in MUAs supporting soft wrapping compared to the ones sent with the default PHP mail plugin.

The Symfony mailer plugin from this MR addresses #3174760: [PP-1] Mails resembling HTML are corrupted. Markup generated by custom or contrib modules might be rendered with visible HTML tags if they are using plain strings instead of MarkupInterface.

By default, the symfony mailer plugin uses sendmail://default as the transport DSN. I.e., it attempts to use /usr/sbin/sendmail -bs in order to submit a message to the MTA. Sites hosted on operating systems without a working MTA (e.g., Windows) should configure an alternative DSN (e.g., SMTP, see below).

Manual testing instructions

With this patch in place (and composer dependencies installed), use the following drush command to switch the mail plugin:

drush config:set system.mail interface.default symfony_mailer

In order to configure the DSN, use the following command:

  • For the default sendmail transport:
    drush config:set system.mail mailer_dsn sendmail://default
  • For mailhog on localhost:
    drush config:set system.mail mailer_dsn smtp://localhost:1025
  • For authenticated SMTP:
    drush config:set system.mail mailer_dsn smtp://user:pass@smtp.example.com:25

Security considerations

The mailer_dsn key in system.mail config stores the symfony mailer data source name. This is used to select the mailer transport. Examples of valid DSN include null://null, smtp://user:pass@smtp.example.com:25 or sendmail://default. Many DSN also take additional options in form of URL query parameters.

The sendmail transport optionally takes a command option used to specify the path to the sendmail binary. Accounts with write access to the mailer_dsn key in system.mail may use this option to execute any binary on the host accessible by the web server process.

Impact on contrib

The contrib Drupal Symfony Mailer module declares a dependency on the symfony mailer component as well. Version requirements over there currently are symfony/mailer": "^5.3 || ^6.0. Sites currently having this module enabled might unexpectedly upgrade to a different version of the symfony mailer component when upgrading to a Drupal version including this MR.

Remaining tasks

Raise a follow-on issue to factor out the transport service.

User interface changes

None.

API changes

None.

Data model changes

Add new config key mailer_dsn in system.mail.

Release notes snippet


Viewing all articles
Browse latest Browse all 299379

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>