.. _mailqueue: ############################# 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 :ref:`one_email_per_to`), 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. .. image:: _static/mailqueue_page.jpg :height: 447px :width: 940px :scale: 100% :alt: Mailqueue ***** 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 :ref:`option_deferred_sending`. 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 :ref:`create_custom_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. .. image:: _static/mailqueue_log.jpg :height: 265px :width: 969px :scale: 100% :alt: Mailqueue log 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. .. _create_custom_intervals: ************************************ 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. .. image:: _static/mailqueue_custom_intervals.jpg :height: 658px :width: 811px :scale: 100% :alt: Custom intervals 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. .. image:: _static/mailqueue_recurrence.jpg :height: 173px :width: 385px :scale: 100% :alt: Recurrence