From Swift Mailer to Symfony Mailer
Few years back, we covered the installaton and configuration drupal swiftmailer. However swiftmailer is no longer maintain and it will be replaced by Symfony Mailer.
This new module is still under alpha release at the time of writing this article (Alpha 10). This is a first overview and implementation of this module. For testing purpose, we have installed the module with our back-office application and implemented a custom development for our module ek_messaging whose purpose is to send message with HTML email notification. To Learn more about the back-office tools and this specific module, go to documentation.
Installation
The best way to install Symfony Mailer is to use composer:
composer require drupal/symfony_mailer
Note that this module is compatible with Drupal 9.1 or higher. Once the module is installed, you can enable it as you normally enable a Drupal module.
There are 2 modules, the first one is the core mailer module and the second manages backward compatibilities with swiftmailer. You need to enable it if your installation or modules sending emails are configured to use swiftmailer.
Migration
If you already use Swiftmailer, the migration is automated. You can import swifmailer configurations into symfony mailer automatically. The documentation of symfony mailer module already describes the process in details and we will not replicate it here.
Overall, the migration is very smooth.
First test email
While swiftmailer required module interface Mail System, Symfony Mailer integrates all functionalities to configure and send email. The last release has a tab to send a test email and validate configurations:
/admin/config/system/mailer/test
The mailer user interface allows you to directly edit and change email policies for each email type and subtype (know in swifmailer development as module and key). As module documentation states:
There are many possible policies to apply including: subject; body; addresses (from, to, ...); theme, transport, convert to plain text. Each policy can be set globally or for emails of a specific type.
For the test email we have configured the body, title and theme (note: for the theme we also used a custom twig template which will be explained on next article):
Integration
In part 2 of this review, we will go deeper into the integration of custom module with custom plugin to pass email parameters, build and send HTML email using symfony mailer.
Add new comment