Swiftmailer is abandoned and will be replaced by Symfony Mailer : check our post about Symfony Mailer
In a previous post from 2015, we described usage of Swift Mailer module to send HTML mail and mail with attachment. At this time, the module was not yet available for Drupal 8.
There is now a version alpha1 available. Let's go through installation process.
Because it has been rather tedious for us, we will try to explain the flow of the process as much as possible to help you save time.
The prerequisite is the installation of composer.
In our case we installed first on Windows inside a folder named F:\Program Files\composer2\.
The installation exe for Windows can be found here.
However, it did not work in our case and we needed to install it manually with the below command (see more details here):
php -c C:\windows\php.ini -r "eval('?>'.file_get_contents('https://getcomposer.org/installer'));"
Once installed you will get the confirmation message:
Installation on Ubuntu server was very easy (see how):
2) Composer manager install and init
If you try to install the Swift Mailer module now, without dependencies, you will get the following error message:
Thus we will use composer manager to install the library as suggested by the module.
Our version of composer manager is 8.x-1.0-rc1+0-dev. After installing the module (/admin/modules), the status report (/admin/reports/status) indicates that the module has to be initialized:
Not initialized Run the module's
Init.php is in Drupal_path/modules/composer_manager/scripts/. We use the following command in Windows to do the initialization as required:
\Drupal path\modules\composer_manager\scripts\php init.php
Then we get the confirmation as follow:
For Ubuntu, the process is similar:
What happened in practice is that the "composer.json" file located in Drupal root has been updated as in the example below:
"Drupal\\composer_manager\\Composer\\": "F:\\path to module\\composer_manager/src/Composer"
Going back to the status report now indicates that we can run drupal-update to update modules dependencies via composer:
Composer update needed. Run
Composer-manager has its own report as well with the following indications:
3) Update dependencies
From windows command line, run "composer drupal-update" from within the Drupal installation root:
If you get an error, you can also run the update by pointing to the composer file as per example below:
The libraries will be updated accordingly and specifically those needed by Swift Mailer:
You can check that in the folder \Drupal\vendor the swiftmailer and html2text folder are now present.
For Ubuntu, the process is the same for dependencies update:
4) Install Swift Mailer
Ok, now you can try again to install Swift Mailer module.
At this point, you may still have the error above about missing library which is weird since we just updated it.
Actually, it may be possible that composer did not update the autoloader properly (bug?). You may solve this by running the command
After this you should get the expected result:
We hope you can benefit from this experience.
Feel free to leave a comment or question if you have any.
On a next post we will see how we use Swift Mailer to attach documents to mail.