How to send emails by batches?

Created on 14 March 2025, about 1 month ago

Just started to use Drupal Symfony Mailer and Symfony Mailer Queue which seem promising. Thanks for the job already done!
I have this scenario where I have to send one email to all the users of my site. It generates, let's say 200 emails. I would like to split these 200 emails in batches of 12 (for example).
Is there a standard way to do that with Symfony Mailer Queue?

💬 Support request
Status

Active

Version

1.1

Component

Miscellaneous

Created by

🇫🇷France gbmapo

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @gbmapo
  • 🇩🇪Germany simonbaese Berlin

    @gbmapo Thanks for the question. Technically, this module does not use batches. It uses queues.

    The feature you are asking for is the responsibility of the queue itself. However, the Symfony Mailer Queue module implements a queue worker independent of the actual queue implementation.

    A queue worker only implements what should be done to process a single item. You can see this in the Drupal\Core\Queue\QueueWorkerInterface::processItem() method.

    In the default setup, you would process the database queue with a cron job. The relevant processQueue() method can be found in Drupal\Core\Cron. Unfortunately, there is no option to limit the processed items here.

    You may consult the implementation in Drush for limiting the processed items. You can use the command drush queue:run symfony_mailer_queue --limit=10 with the respective flag. The relevant code can be found in Drush\Commands\core\DrushCommands::run().

    This feature most likely will not make it into this module. However, this module offers the option to "rate limit" the email sending with the "Wait time per item" configuration option. Maybe that suits your concerns.

    Other options may exist when using more advanced queues such as RabbitMQ.

    Feel free to follow up with more questions.

  • 🇫🇷France gbmapo

    Would it be possible to run drush queue:run symfony_mailer_queue --limit=10 with a cron job?
    I use Ultimate Cron on my site.

Production build 0.71.5 2024