Mail Queue (deferred sending)¶
If you are using Post Status Notifier to send email notifications to many users you could face page loading issues when a post gets updated and a PSN rule matches. This is because PSN by default generates and sends all emails in realtime, meaning at the moment you click the Publish button. If your rule would for example create several thousands of emails (e.g. by using PSN’s One email per TO recipient), the editor page would load until all those mails have been sent.
To reduce the server load in case of large amounts of generated emails, PSN has a “Deferred sending” feature. If activated, the emails will not get send in realtime but being stored in a mail queue for later processing. Nevertheless there will be some server load when the large amount of email data will be transferred to the mail queue, but it will be much faster compared to the real time sending.
The Deferred sending feature can be activated on PSN’s option page. For a detailed explanation of all options of this feature see the options manual Mail Queue.
When activated, PSN will put all generated emails in the mail queue instead of sending them directly. Every time the mail queue runs, a configurable amount of emails will be processed and sent.
How many emails should be send in an mail queue run can be configured with the option “Max amount”. This depends on your server’s performance and how many mails you are about to send.
If you’re sending 500 emails, and you need to send them in 5 hours, make sure you set the max amount to 100 and recurrence to every hour or max amount 25 with a recurrence of every 15 minutes and so on.
With “Max tries” you can define a limit for how many times the mail queue process will try to send an email if an error occurs. When the number of max tries is reached for an email it will be skipped.
With “Recurrence” you can define how often the mail queue process should run automatically. It relies on WordPress’s built-in Cron API. By default there will be only three recurrence options: “Once Hourly”, “Once Daily” and “Twice Daily”. Those are the built-in options and not suitable to run a mail queue. You need shorter intervals to send a large amount of queued emails. This can be done by creating custom intervals. I recommend using the plugin WP Crontrol to create custom cron intervals (see Creating custom recurrence intervals).
Note that the recurrence is an approximate value as the WP Cron API is not like a real cronjob. It will only run if there is any action on your site, like a page visit.
Log sent emails¶
If you want to track outgoing mails, you should activate this option because successfully sent emails get deleted from the mail queue to keep the database table lean. If the logging is active, sent email get copied to the log table. You can switch to the log by clicking the “Log” navigation item in the top of the mail queue page.
Run after add¶
If you want the mail queue to be run once immediately after emails got added, select this option. This will send the first bunch of the configured max amount directly without having to wait for the next scheduled cron run.
Creating custom recurrence intervals¶
After you have installed the plugin WP Crontrol change to its setting page (Setting / Cron Schedules). There you can add a new cron schedule interval.
For example let’s create an interval with 60 seconds. You can insert whatever you want for “Internal name” and “Display name”. Set the “Interval (seconds)” to 60.
After you have added this new interval you can change back to the PSN options page and select this interval for “Recurrence”. Now the mail queue would run every minute and send the configured max amount of scheduled emails.