Mail Queue (deferred sending)Âķ
IntroductionÂķ
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.
SetupÂķ
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.
Max amountÂķ
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.
Example:
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.
Max triesÂķ
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.
RecurrenceÂķ
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
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.