Some time ago I talked about a way to “throttle” down email queues to try and prevent being blacklisted for sending hundred’s of legit emails in one batch. The process which can be seen in more depth here released emails over a period of time in batches of 50 to try and reduce the load.

It has been some time since that and I have seen a massive reduction in those accounts being blacklisted for SPAM which is a HUGE success (and relief). Since that time though I have been thinking about the ability to add email alerting into My Book It and how that would look.

What I want to avoid is having each site sending out emails all over the place, the method needs to be controlled in a manner that it is reliable and efficient.

With all this in mind I have made some changes to the way the process works. Firstly email will flow from the admin panel and not directly from the sub domains. (i.e. if a site wants to send email, it will submit it to a central queue for processing). This will be fine except that some emails need to be sent before others (i.e. an alert for an upcoming class or change needs to go before a general newsletter)

So I have updated my Database table to look like.

Lets go through the columns and what they do.

  • ┬áID – Primary key
  • Submission_date – Date the email was submitted to the queue, mostly for auditing
  • Sender – The email address that the account wants attached to the sender of the email as they will be coming in from all different addresses
  • Recipient – The recipient of the email
  • Subject – Subject of the email
  • Message – The body of the email
  • Headers – This is actually no longer required
  • Status – Either queued or sent
  • Sent_date – The date the message was sent – Again for auditing
  • Sent_by – A record of what account sent the message, for auditing
  • do_not_send_before – This is so emails can be queued for future sending, this ties in with the new workflow manager
  • priority – A numeric priority for the emails to allow messages to be bumped up the queue.

Now that we have all of those fields I have also added two Settings to the Global Settings

  • Email Running – This is a yes or no option to stop mail from sending if required
  • Email Batch – A number of how many emails will be sent in one go

The mailer.php has also been updated to use PHPMailer rather then mail as I want to send all messages out via a mail server in the network to take any load off the webserver itself. (Plus it will allow me to send out via different IP addresses in the future.

So the script now looks like

And that is it, the mailer is now ready to start accepting messages from other sub domains. (more on how that happens later)