0

I have some rules set up to send email notifications for forum messages, comments and articles. Sometimes the number of users that need to receive the email are quite large and the page doesn't refresh before the server has sent all the emails. Can the sending be done in the background something? Isn't that what the core module "Queue" is there for?

0

Oh the joys of email. Email is sent via the servers underlying or configured MTA. PHP merely passes-off the email content to be delivered. Depending on your email configuration PHP may wait for bounce notifications for example ... or simply spool the emails to disk and wait for the MTA to flush the outgoing mail folder.

Emails from Drupal though do not need to occur on page-load or form submission. If you want you could use Rules to slowly fill a Queue (a "list") of emails to send out from the "website" periodically.

Depending on how you want to process that Queue, whether in realtime using a Process or Job/Worker library is up to you. Or you could batch up the sending of the emails using Drupal (and/or Drush) and it's built in Cron support.

Or, for instance you could use one of the many email campaign modules for Drupal such as:

to completely offload the work from your server. How you wish to approach this problem, it's feasibility and cost are up to you.

EDIT:

This module works to provide Rules to fill Queues using Drupal Entities, Rules Queue. Google is your friend! :D

For some example code that uses hook_cron to send Queue'd emails: http://www.jide.fr/english/using-rules-and-the-queue-api-to-batch-send-mass-mails

  • But how do I actually fill a queue from rules? – Turion Sep 4 '14 at 22:32
  • @Turion please see my edit. – tenken Sep 4 '14 at 22:40
  • I've seen this module, but it has only 1 commit, no releases and absolutely no activity. That won't work I'm afraid :/ But thank you for your many other hints! – Turion Sep 7 '14 at 14:58
0

An easy solution is to go with Queue Mail. It queues all mail sent from Drupal and sends it via a cron job.

If doing this, one should make sure that there is an actual cron job on the server calling the Drupal cron.php regularly, as explained in https://www.drupal.org/node/23714. Otherwise, the occasional visitor might trigger cron and be annoyed by the huge latency. I set it up to call cron.php every 5 minutes, so the notifications are sent within a decent time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.