Drupal 9.3 and Swift Mailer

This article is updated on December 10th, 2021 to reflect recent developments on this subject.

Drupal 9.3 will be released on December 8, 2021. Updating from 9.2 should be painless, but if you are using the Swift Mailer module then you'll probably encounter some issues.

At the moment of writing this article, it's not possible to update to Drupal 9.3 RC due to conflicting dependencies. If you try to update this is what you'll see:

Problem 1
    - drupal/swiftmailer[2.0.0-beta1, ..., 2.0.0] require egulias/email-validator ^2.0 -> satisfiable by egulias/email-validator[2.0.0, ..., 2.1.x-dev (alias of dev-master)].
    - egulias/email-validator 2.1.x-dev is an alias of egulias/email-validator dev-master and thus requires it to be installed too.
    - You can only install one version of a package, so only one of these can be installed: egulias/email-validator[dev-master, 2.0.0, ..., 2.1.x-dev, 3.0.0, ..., 3.x-dev].
    - drupal/core-recommended 9.3.0-rc1 requires egulias/email-validator 3.1.2 -> satisfiable by egulias/email-validator[3.1.2].
    - Root composer.json requires drupal/core-recommended ^9.3@RC -> satisfiable by drupal/core-recommended[9.3.0-rc1].
    - Root composer.json requires drupal/swiftmailer ^2.0@beta -> satisfiable by drupal/swiftmailer[2.0.0-beta1, 2.0.0].

As you can see the latest version of Drupal requires egulias/email-validator version 3.1.2 while Swift Mailer requires egulias/email-validator version 2.

Swift Mailer module is marked as obsolete because it depended on the Swift Mailer library which is no longer maintained. That's why it probably won't be possible to use Swift Mailer and Drupal 9.3 together.

To update your project to Drupal 9.3 you should uninstall Swift Mailer module and install Symfony Mailer module, which depends on the Symfony Mailer library.

Symfony Mailer is considered the next evolution of Swift Mailer. It comes with the same set of features giving support of HTML emails, multipart messages, file attachments, Twig integration, CSS inlining, embedded images, third-party integrations, signing and encryption, async sending, load-balancing, and much more features.

Symfony Mailer also doesn't have a dependency on the Mail System module, because it's a complete mail system that replaces the one that's in Drupal Core. That also means one less dependency for your project.

The only downside to all this is that there's no stable release of the Symfony Mailer module. All you can find at the moment is the alpha version. So, test the module thoroughly before using it in production.

Upgrade path from Swift Mailer

Uninstall and remove Swift Mailer and Mail System modules:

drush pm-uninstall swiftmailer
drush pm-uninstall mailsystem
composer remove drupal/swiftmailer

and install Symfony Mailer and Symfony Mailer Back-compatibility modules:

composer require drupal/symfony_mailer
drush en symfony_mailer
drush en symfony_mailer_bc

Now go to the Mailer settings page /admin/config/system/mailer and configure the transport type you want to use.

In my case I deleted the default native transport type:

Symfony Mailer - Drupal 9 - Native transport
Symfony Mailer - Drupal 9 - Native transport

and created a new SMTP transport:

Symfony Mailer - Drupal 9 - SMTP transport
Symfony Mailer - Drupal 9 - SMTP transport
Symfony Mailer - Drupal 9 - SMTP transport
Symfony Mailer - Drupal 9 - SMTP transport

While testing the module, I encountered a small issue. So, I fixed it and created a merge request.

… and that’s it! Now go on and update some mailers. And if you need help with anything let me know.

December 10th, 2021 update

The latest version of the Swift Mailer module can be used together with Drupal 9.3 because the dependency conflict with drupal/core-recommended has been fixed. So, as a short-term fix update the module to version 2.2 or newer, but keep in mind that this module is obsolete and you should plan to upgrade to Symfony Mailer as soon as possible.

About the Author

Goran Nikolovski is a creator, speaker, open-source contributor, web developer specialized in Drupal and DevOps enthusiast. He is the founder of this website and he enjoys sharing his knowledge and experiences.