signed-mail-gateway has two halves in one repository: a Cloudflare Worker that sends mail through Cloudflare Email Sending, and a WordPress plugin that sends every wp_mail() call to it. It is for operators whose host blocks outbound SMTP or who do not want mail credentials on the web server. It is MIT licensed, and v0.1.0 was released on 14 November 2026.
A WordPress site sends account mail through wp_mail(): sign-in codes, password resets, comment notices. On many hosts that path is fragile. VPS providers block outbound SMTP ports by default, so wp_mail() fails with a connect timeout and sign-in mail stops, often silently.
The usual fixes carry their own risk. SMTP credentials on the web server let anyone who reads them send as the domain from anywhere. A plain HTTPS mail API key on the origin has the same weakness: a leaked key sends any mail as any address it allows, and a captured request can be replayed. Cloudflare Email Sending can be called only from a Worker, so a Worker has to sit in the middle, and the question is how it should trust the caller.
/v1/send only if it carries a valid HMAC-SHA256 signature over timestamp, nonce and body.send_email binding for that domain.pre_wp_mail, signs the request, and classifies every attempt into one outcome.check, status and send-test.wp_mail() -> pre_wp_mail (client) -> build like core, phpmailer_init on a private PHPMailer
-> encode JSON once -> sign "<ts>.<nonce>.<body>" -> POST /v1/send (no redirects)
Worker: path, method -> config -> size -> header shape -> HMAC verify (current, then next)
-> clock skew -> claim "<ts>.<nonce>" in the Durable Object -> parse -> validate -> send_email binding
The Worker is TypeScript with no runtime dependencies. It authenticates first: nothing is parsed or stored before the signature verifies, and the skew check comes after the signature, so an unsigned caller does not learn the Worker’s clock. Verification uses constant-time Web Crypto verify.
Replay protection is a single SQLite-backed Durable Object, NonceStore. It claims the key <timestamp>.<nonce> with one synchronous insert, so two racing copies of one request give exactly one send. Keys are kept for twice the skew, each claim deletes a few expired keys, and an alarm sweeps when traffic stops. The nonce is claimed before the message is validated, so every retry needs a fresh timestamp and nonce.
The client ends every attempt in exactly one class: sent, suppressed, rejected, retry, quota, unavailable or unknown. The core path is tried only after unavailable, quota or retry. A timeout is unknown and never falls back, because a second copy by SMTP is worse than a reported failure. The client also fires wp_mail_succeeded and wp_mail_failed itself, so mail logging plugins keep working.
The README setup uses placeholder names. In wp-config.php:
define( 'SIGNED_MAIL_GATEWAY_URL', 'https://mail-gateway.example.org' );
define( 'SIGNED_MAIL_GATEWAY_SECRET', 'the-64-hex-characters-from-step-2' );
Then wp signed-mail-gateway check must print key slot current. Any other language can call the gateway by signing <timestamp>.<nonce>.<body>. The repository ships test-vectors/v1.json, used by both test suites, for checking a client.
https:// URL, and signs the bytes it sends.auth_failed (with SMTP fallback) until the client catches up.E_SENDER_NOT_ALLOWED as if it were a Cloudflare error code. The review checked the public docs, found none, and moved the classification to the error’s wording, with new tests.allowed_sender_addresses on each binding. The docs now state that the binding is account-level and allowed senders belong in the dashboard.var_dump output with #[\SensitiveParameter] and a redacting __debugInfo(). HTML-to-text moved from PHPMailer’s converter to a small in-repo one with 26 edge-case tests.sender_not_allowed classification to be confirmed against a live binding refusal.Test status: this is v0.1.0, tested on stubs and mocks. The review reports 156 Worker tests (running in the Workers runtime), 167 PHPUnit tests, PHPStan level 8, eslint and phpcs clean, and a wrangler deploy --dry-run that passes with no account. It has not been deployed against a live Email Sending binding, and CI has not yet run on GitHub. It was specified, built and reviewed in separate roles by language-model coding agents under the editor’s direction.
The Worker needs a Cloudflare account with Email Sending enabled, an onboarded sending domain, and Node 20 or later. The plugin needs PHP 8.1 or later and WordPress 6.4 or later, with no Composer at runtime.
git clone https://github.com/IndianOpinion/signed-mail-gateway.git
cd signed-mail-gateway/worker
npm ci
npx wrangler secret put GATEWAY_SECRET
npx wrangler deploy
Then copy client/ to wp-content/plugins/signed-mail-gateway/ and activate it.