Developer overview
Stacko Mail replaces only the transport of wp_mail(). Plugins keep calling wp_mail() as usual, and core’s mail filters and actions keep working.
- Requires WordPress 6.5+ and PHP 8.1+.
- PSR-4 namespace
Stacko\Mail, inincludes/. - The admin screens are a Vue 3 app (source in
src/, built tobuild/) that talks to the plugin’s REST API.
The send pipeline
Section titled “The send pipeline”Stacko Mail hooks the core pre_wp_mail filter at priority 99.
- If another plugin already short-circuited
wp_mail()(returned a non-null value earlier), Stacko Mail does nothing. - If the primary connection is WordPress default or no connection is set up, Stacko Mail returns
nulland core sends the email with PHPmail()as usual. The email is still logged through core’swp_mail_succeededandwp_mail_failedactions. The exception is when thestacko_mail_take_over_defaultfilter returnstrue(email control does this while pausing or redirecting). Stacko Mail then handles the email itself. - Otherwise, Stacko Mail builds a
Stacko\Mail\Mail\Messagefrom thewp_mail()arguments. It applies core’swp_mail_from,wp_mail_from_name,wp_mail_content_typeandwp_mail_charsetfilters, the same way core does. - The message passes through the
stacko_mail_messagefilter. Returningnullblocks the email (error codeblocked). - The message is sent through the primary connection. If that fails, it is sent through the backup connection, unless the failure was caused by the message itself (
invalid_address,no_recipients,attachment_failed,blocked). stacko_mail_after_sendfires with every attempt. The logger, alerts and stats listen here.- Core’s
wp_mail_succeededorwp_mail_failedfires, so other plugins see the result. On failure, theWP_Errordata includes astacko_mail_error_codekey with the error code. wp_mail()returnstrueorfalse.
Compatibility with core hooks
Section titled “Compatibility with core hooks”| Core hook | Behaviour |
|---|---|
wp_mail filter |
Runs as usual (core applies it before pre_wp_mail). |
wp_mail_from, wp_mail_from_name, wp_mail_content_type, wp_mail_charset |
Applied when the message is built. |
phpmailer_init |
Fired for the Other SMTP mailer and for WordPress default used as a backup. Not fired for API mailers (Brevo, SendGrid, Mailgun, Postmark), which don’t use PHPMailer. |
wp_mail_succeeded, wp_mail_failed |
Fired once per email with the final result. |
Stacko Mail’s own From settings use wp_mail_from and wp_mail_from_name at priority 999, and the Return-Path option uses phpmailer_init at priority 999.
Running alongside another SMTP plugin
Section titled “Running alongside another SMTP plugin”If another SMTP plugin also hooks pre_wp_mail at an earlier priority and short-circuits it, that plugin sends the email and Stacko Mail steps aside. Deactivate the other plugin after importing its settings.
Mailers
Section titled “Mailers”Each way of sending is a mailer implementing Stacko\Mail\Mailers\MailerInterface:
| ID | Label | Transport |
|---|---|---|
brevo |
Brevo | HTTPS API (api.brevo.com) |
sendgrid |
SendGrid | HTTPS API (api.sendgrid.com or api.eu.sendgrid.com) |
mailgun |
Mailgun | HTTPS API (api.mailgun.net or api.eu.mailgun.net) |
postmark |
Postmark | HTTPS API (api.postmarkapp.com) |
smtp |
Other SMTP | PHPMailer over SMTP |
default |
WordPress default | PHP mail() |
A mailer declares its settings fields with schema(). The admin form is generated from that schema, so a new mailer needs no frontend code. Add mailers with the stacko_mail_mailers filter.
Where the email came from
Section titled “Where the email came from”The log’s “Sent by” value comes from a backtrace of the wp_mail() call. It is the plugin or theme folder slug (for example woocommerce), core for WordPress itself, or empty when unknown. Stacko Mail’s own emails use stacko-mail-test (test emails) and stacko-mail-alert (alert emails). It’s available as $message->source.
Permissions
Section titled “Permissions”Every admin screen, REST route and AJAX action requires the manage_options capability (manage_network_options on multisite), plus a WordPress nonce. Change the capability with the stacko_mail_capability filter.
Stored data
Section titled “Stored data”| Where | What |
|---|---|
{prefix}stacko_mail_logs |
One row per email. |
{prefix}stacko_mail_events |
Timeline events per email (attempts, fallback, resends). |
{prefix}stacko_mail_stats_daily |
Daily counts by status and source. |
stacko_mail_settings option |
General settings. |
stacko_mail_connections option |
Primary and backup connections. Secret fields are encrypted. |
stacko_mail_alerts option |
Alert channels and rules. Webhook URLs are encrypted. |
On multisite, these are per site.
Encryption
Section titled “Encryption”Passwords, API keys and webhook URLs are encrypted with libsodium (sodium_crypto_secretbox). The key comes from STACKO_MAIL_ENCRYPTION_KEY if it’s defined, otherwise from the AUTH_KEY and SECURE_AUTH_SALT constants. There is no plaintext fallback. Secrets are never sent to the browser, exports, logs, transcripts or diagnostic reports.
Scheduled tasks
Section titled “Scheduled tasks”| Cron hook | Schedule | Purpose |
|---|---|---|
stacko_mail_retention |
Daily | Deletes log rows older than the retention period. |
stacko_mail_send_alert |
Single events | Sends one alert in the background. |
Both are internal. They are removed on uninstall when the user chose to delete data.
Outbound requests
Section titled “Outbound requests”All HTTP requests use wp_safe_remote_*. Webhook URLs for alerts must be HTTPS, and Slack, Discord and Teams URLs must match that service’s domain.
Building from source
Section titled “Building from source”The human-readable source of the admin app is included in src/. To rebuild build/:
npm ci && npm run build