Total Mail Queue
Take Control and improve Security of wp_mail(). Queue and log outgoing emails, and get alerted, if your website wants to send more emails than usual.
by Alex Meusburger · github.com/rpgmem/total-mail-queue · website
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/rpgmem/total-mail-queue/archive/refs/heads/main.zipReadme
=== Total Mail Queue === Tags: email, mail, queue, email log, wp_mail Requires at least: 5.9 Tested up to: 6.9 Stable tag: 2.9.0 Requires PHP: 7.4 License: GPLv3 or later License URI: https://www.gnu.org/licenses/gpl-3.0.html
Queue outgoing emails, manage SMTP accounts with daily/monthly limits, and get alerts if your site sends too many emails.
== Description ==
This plugin enhances the security and stability of your WordPress installation by delaying and controlling wp_mail() email submissions through a managed queue.
If your site exhibits unusual behavior — such as a spam bot repeatedly submitting forms — you will be alerted immediately.
- Intercepts wp_mail() and places outgoing messages in a queue
- Configure how many emails are sent and at what interval
- Manage multiple SMTP accounts with priority, daily and monthly sending limits
- Test SMTP connections before sending
- Log all queued email submissions with status filter (sent / error / alert)
- Auto-retry failed emails with configurable retry limit
- Resend or force-resend failed emails from the log
- Receive alerts when the queue grows unexpectedly
- Receive alerts when WordPress is unable to send emails
- Export/import plugin settings and SMTP accounts via XML
- Detects and resolves conflicts with other email plugins
This plugin is a fork of Mail Queue by WDM.
== Frequently Asked Questions ==
= Do I need to configure anything? =
Yes. Once activated please go into the Settings of the Plugin to do some configurations.
You can enable the Queue, control how many emails and how often they should be sent.
You can enable the Alerting feature and control at which point exactly you want to be alerted.
= How does this plugin work? =
When enabled, the plugin intercepts wp_mail(). Instead of sending emails immediately, they are stored in the database and released gradually via WP-Cron according to your configured interval.
= Does this plugin change the way HOW the emails are sent? =
It depends on your configuration. In the default auto send method the plugin preserves whatever email delivery mechanism you already have (SMTP from another plugin, PHP mail, Mailgun, etc.).
If you configure SMTP accounts within the plugin, it will use those to send emails with full control over daily/monthly limits. You can also set the send method to php to always use WordPress's default mail function.
= Does this plugin work, if I have a caching Plugin installed? =
If you're using a caching plugin like W3 Total Cache, WP Rocket or any other caching solution which generates static HTML files and serves them to visitors, you'll have to make sure you're calling the wp-cron file manually every couple of minutes.
Otherwise your normal WP Cron wouldn't be called as often as it should be and scheduled messages would be sent with big delays.
= What about Proxy-Caching, e.g. NGINX? =
Same situation here. Please make sure you're calling the WordPress Cron by an external service or your webhoster every couple of minutes.
= My form builder supports attachments. What about them? =
You are covered. All attachments are stored temporarily in the queue until they are sent along with their corresponding emails.
= What are Queue alerts? =
This is a simple and effective way to improve the security of your WordPress installation.
Imagine: In case your website is sending spam through wp_mail(), the email Queue would fill up very quickly preventing your website from sending so many spam emails at once. This gives you time and avoids a lot of trouble.
Queue Alerts warn you, if the Queue is longer than usal. You decide at which point you want to be alerted. So you get the chance to have a look if there might be something wrong on the website.
= Can I add emails with a high priority to the queue? =
Yes, you can add the custom X-Mail-Queue-Prio header set to High to your email. High priority emails will be sent through the standard Total Mail Queue sending cycle but before all normal emails lacking a priority header in the queue.
Example 1 (add priority to Woocommerce emails):
add_filter('woocommerce_mail_callback_params',function ( $array ) { $prio_header = 'X-Mail-Queue-Prio: High'; if (is_array($array[3])) { $array[3][] = $prio_header; } else { $array[3] .= $array[3] ? "\r\n" : ''; $array[3] .= $prio_header; } return $array; },10,1);
Example 2 (add priority to Contact Form 7 form emails):
When editing a form in Contact Form 7 just add an additional line to the
Additional Headers field under the Mail tab panel.
X-Mail-Queue-Prio: High
Example 3 (add priority to WordPress reset password emails):
add_filter('retrieve_password_notification_email', function ($defaults, $key, $user_login, $user_data) { $prio_header = 'X-Mail-Queue-Prio: High'; if (is_array($defaults['headers'])) { $defaults['headers'][] = $prio_header; } else { $defaults['headers'] .= $defaults['headers'] ? "\r\n" : ''; $defaults['headers'] .= $prio_header; } return $defaults; }, 10, 4);
= Can I send emails instantly without going through the queue? =
Yes, this is possible (if you absolutely need to do this).
For this you can add the custom X-Mail-Queue-Prio header set to Instant to your email. These emails are sent instantly circumventing the mail queue. They still appear in the Total Mail Queue log flagged as instant.
Mind that this is a potential security risk and should be considered carefully. Please use only as an exception.
Example 1 (instantly send Woocommerce emails):
add_filter('woocommerce_mail_callback_params',function ( $array ) { $prio_header = 'X-Mail-Queue-Prio: Instant'; if (is_array($array[3])) { $array[3][] = $prio_header; } else { $array[3] .= $array[3] ? "\r\n" : ''; $array[3] .= $prio_header; } return $array; },10,1);
Example 2 (instantly send Contact Form 7 form emails):
When editing a form in Contact Form 7 just add an additional line to the
Additional Headers field under the Mail tab panel.
X-Mail-Queue-Prio: Instant
Example 3 (instantly send WordPress reset password emails):
add_filter('retrieve_password_notification_email', function ($defaults, $key, $user_login, $user_data) { $prio_header = 'X-Mail-Queue-Prio: Instant'; if (is_array($defaults['headers'])) { $defaults['headers'][] = $prio_header; } else { $defaults['headers'] .= $defaults['headers'] ? "\r\n" : ''; $defaults['headers'] .= $prio_header; } return $defaults; }, 10, 4);
= Can I still use the wp_mail() function as ususal? =
Yes, the wp_mail() function works as expected.
When calling wp_mail() the function returns true as expected. This means the email has been entered into the queue.
Exceptions:
If for some reason the email cannot be entered into the database, wp_mail() will return false.
However if you send an email using the instant header option the email will be considered important. In this case the email will be sent right away, even if there is an error creating a log for it in the queue.
= I have a MultiSite. Can I use Total Mail Queue? =
Yes, but with limitations.
Do not activate the Total Mail Queue for the whole network. Instead, please activate it for each site separately. Then it will work smoothly. In a future release we'll add full MultiSite support.
== Installation ==
Upload the the plugin, activate it, and go to the Settings to enable the Queue.
Please make sure that your WP Cron is running reliably.
== Changelog ==
The two most recent releases are summarised below. The full history of every release is in CHANGELOG.md.
= 2.9.0 =
- New: plugins can label each of their emails as a distinct source by setting an
X-TMQ-Source-Key(and optionalX-TMQ-Source-Label) header. The queue reads it as the highest-priority source strategy — ahead of the built-in listeners and the caller backtrace — and strips both headers before delivery, so a plugin whose mail all flows through one wrapper can still split its emails into per-feature sources. Onlyplugin:/mu_plugin:/theme:keys are accepted. - New: any source can be pinned to a preferred SMTP account on the Sources → edit screen. The queue sends through that account when it is enabled and under quota, and transparently falls back to the normal account rotation when it is capped, disabled, or removed — a preference never blocks or delays a send.
- Fixed: the "queue may not be processing" admin notice no longer fires during healthy operation — it now keys off the last successful send (over two hours idle) with the worker not scheduled to act, instead of the last worker run.
= 2.8.0 =
- New: a persistent per-email error log with an optional full SMTP debug transcript, a specific "why is the queue waiting?" message when every account is capped, and a proactive "queue may not be processing" admin notice for cached / low-traffic sites.
- Fixed: per-cycle SMTP quotas no longer get stuck; SMTP passwords no longer fail to decrypt intermittently; the queue no longer freezes when a send hangs (the cron lock now has a real self-expiring TTL).