Integrations

WordPress

Install the Ternwire WordPress plugin to send password resets, form notifications, and store receipts through the Ternwire API.

On this page

The Ternwire WordPress plugin sends every email your site creates through the Ternwire API. That covers password resets, new user notices, contact form submissions, and WooCommerce receipts. It replaces delivery inside wp_mail(), so other plugins keep working unchanged and email leaves over HTTPS instead of SMTP. Many hosts block outbound SMTP, so this works where an SMTP plugin cannot.

Install and connect

  1. Download the Ternwire plugin (zip). In WordPress, open Plugins, choose Add New Plugin, then Upload Plugin, and upload the zip. Activate it. The plugin needs WordPress 5.9 and PHP 7.4 or later.
  2. Create an API key with sending access in the Ternwire dashboard. Open Settings, then Ternwire, and paste the key.
  3. Set the From address to an address on an active sending domain. It replaces the wordpress@ default. Tick the option below it to also replace From addresses that other plugins set.
  4. Send a test email from the same page.

Until a key is saved, WordPress keeps sending the default way. To keep the key out of the database, define it in wp-config.php. Constants override the settings page.

define( 'TERNWIRE_API_KEY', 'em_live_...' );
define( 'TERNWIRE_FROM_EMAIL', 'notifications@updates.yourdomain.com' );
define( 'TERNWIRE_FORCE_FROM', true ); // optional

How WordPress email is translated

  • The sender name comes from the From header a plugin sets. Without one, it is your site title. The wp_mail_from and wp_mail_from_name filters still apply.
  • The To, Cc, Bcc, and Reply-To headers become the matching API fields. An address listed twice is sent once, in its first role. Names in these headers are dropped.
  • A text/html content type, set by header or by the wp_mail_content_type filter, sends the body as HTML. Anything else sends it as plain text.
  • Custom X- headers and List-Unsubscribe are kept. Other headers are dropped.
  • Attachments are uploaded and checked before wp_mail() returns. All files of one email together can be up to 15 MB, with at most 20 per email. The plugin checks the total before it uploads anything. The plugin waits up to 30 seconds for the check.
  • Ternwire builds the message itself, so phpmailer_init hooks do not run.

Failures and retries

Each call to the API waits at most 8 seconds, so a slow or unreachable API holds a page request for about 18 seconds at most, plus the attachment check when the email has attachments. A temporary failure, such as no reply, a timeout, a rate limit or a server error, is retried once at once. If that also fails, the plugin keeps the email and tries again in the background through WP-Cron, after 1, 5, 15, 60 and 240 minutes. Every attempt uses the same idempotency key and the same request, so a retry never sends a second copy. Up to 20 emails can wait at a time.

A waiting email counts as handed over, so wp_mail() returns true and fires ternwire_email_queued. If the later attempts also fail, the plugin fires wp_mail_failed with the reason then. A permanent failure, such as an invalid address or an unverified domain, returns false and fires wp_mail_failed at once. Logging plugins record it as usual. WP-Cron runs when someone visits the site, so on a quiet site a waiting email can go out later than planned.

Settings, then Ternwire, lists the last 20 sending problems and how many emails are waiting. A later successful send does not remove them. Clear the list there once you have read it.

Hooks for developers

HookPurpose
ternwire_email_payloadFilters the API request body before it is sent, for example to add tags.
ternwire_attachment_scan_timeoutChanges how many seconds to wait for the attachment check.
ternwire_email_acceptedFires with the accepted message, including its msg_ ID.
ternwire_email_queuedFires with the reason and the wp_mail() data when an email waits for a later attempt.
add_filter( 'ternwire_email_payload', function ( $payload, $atts ) {
    $payload['tags'] = array( 'source' => 'woocommerce' );
    return $payload;
}, 10, 2 );

The Ternwire SMTP relay is coming soon. Until then, use this plugin in place of an SMTP plugin.