Drupal Advent Calendar Door 11: Symfony Mailer

By james, 11 December, 2022
Advent Calendar door 11 containing Symfony Mailer

Welcome back to the Drupal Advent Calendar, and it’s time to open door 11.

Yesterday I talked about storing contact form submissions, but we also need to deliver the emails they generate, so today I am talking about the Symfony Mailer module.

While it’s possible you may not need to do anything special to send email from your website, just let the default PHP handler take care of delivery, this can be highly dependent on how your webserver is configured, and delivery problems can arise.

This is a fairly new module, which takes over the function of two older modules, Mail System and Swift Mailer. Mail System allows you to select how different emails produced by the site are formatted and delivered, and Swift Mailer actually carried out the delivery. Unfortunately, Swift Mailer is no longer supported, and it is unlikely that security vulnerabilities will be fixed if discovered, or that it will receive a version for the forthcoming Drupal 10.

Symfony Mailer is still in Beta, which may cause concerns for site developers, who must decide whether to keep using the unsupported Swift Mailer, or migrate to the new module, which does not yet have a stable release. However, it is active on over 4,500 sites, and there are relatively few open issues. There are some modules that haven’t yet received modifications to support Symfony Mailer, but it has a compatibility mode that supports a lot of modules. However, as modules move to Drupal 10, compatibility with Symfony Mailer is likely to improve.

You may be aware that since version 8, Drupal has been built on the Symfony framework, and this module is so named for its use of Symfony libraries.

The module allows you to define policies for how different emails are generated, allowing emails for different modules to be handled differently if required. You can even configure specific headers to be sent for each email.

The Symfony Mailer policies page

However, for many sites, the most important part of both Symfony Mailer and Swift Mailer is the ability to configure transport settings. Multiple types of Transport are supported, though you are most likely to use either Sendmail, which uses the server’s Sendmail command, or SMTP, which allows you to provide settings to connect to an external SMTP server. Another one which can be useful on development servers is Null, which doesn’t send any emails at all.

The Symfony Mailer transport settings.

So if you’re starting a new site, I’d recommend trying out Symfony Mailer. If you have an existing site running Swift Mailer, you should start looking at Symfony Mailer and start planning your migration to it.

That’s day 11. Hope you’ll join me for another module tomorrow.

Advent Calendar with door 11 open, revealing Symfony Mailer



Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.