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: