email

Do you need speed?

Most of the company managers will admit that a good management system is a key factor for business expansion and efficiency. But one main obstacle for back office system adoption is that in many cases it disrupts current working flow, make people feel their time is not optimized

Queue email

 

When sending email from your application, using queuing process can reduce the application response time and increase speed.

By sending the message to queue instead of sending directly at the end of server response, you may achieve better user experience. Once messages are in queue, you just need a scheduled cron task to initiate scheduled email sending.

How ?

Queuing is simple in Drupal 8

Let's imagine you have a module that currently send an email using mail plugin to multiple users:


foreach (User::loadMultiple($users) as $account) {
    \Drupal::service('plugin.manager.mail')->mail(
            'my_module,
            'my_key',
            $account->getEmail(),
            $account->getPreferredLangcode(),
            $params,
            $from->mail,
            TRUE
         );
}

 

To direct message to queue instead, you can replace with queue service:

Install and use Swift Mailer in Drupal 8 (part 2 : implementation)

 

Swiftmailer is abandoned and will be replaced by Symfony Mailer : check our post about Symfony Mailer

 

In previous article we explained how we installed the Swift Mailer module and its dependencies.

In this second part, let's see how we configure and implement it to use in our modules to send formated HTML mail with attachment.

First you will need to have Mail system module installed already. There is no particular issue or difficulty here.

 

1) Configure Swift Mailer

 

In Swift Mailer configuration (/admin/config/swiftmailer/transport) , we select the following options:

Transport:

Install and use Swift Mailer in Drupal 8 (part 1 : dependency)

 

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.

 

1) Composer

 

The prerequisite is the installation of composer.

In our case we installed first on Windows inside a folder named  F:\Program Files\composer2\.