Repository navigation
fix(mailgun): refuse deleted Mailgun templates before sending; no suppression for ESP blocks - #29
Merged
Merged
Conversation
Mailgun answers 200 "Queued" for a send that names a template it does
not have and drops the message later (event failed, severity temporary,
delivery-status 621 "Template not found"; verified live 2026-11-19), so
Magic Mail logged such mails as sent.
sendViaMailgun now checks the template before a template send:
GET /v3/{domain}/templates/{name}?active=yes (domain scope) or
GET /v4/templates/{name}?active=yes (account scope). A 404 or a template
without an active version throws MAGIC_MAIL_PROVIDER_TEMPLATE_UNAVAILABLE
before any message request (pre-dispatch, fallback-safe). Positive results
are cached for 60 s per account and template; parallel sends share one
check. Network, timeout, auth, 429 and 5xx failures of the check only log
a warning and the send goes ahead.
Docs read: Mailgun templates API reference and its OpenAPI bundle
(documentation.mailgun.com/docs/mailgun/api-reference/send/mailgun/templates,
retrieved 2026-11-19), plus live answers of the US API for unknown and
version-less templates.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…soft bounces A permanent Mailgun failure with reason espblock (seen live: 550 5.7.40, bounce-type soft; Mailgun did not add the address to its bounce list) was mapped to a hard bounce and suppressed the recipient. It is now recorded as blocked and never suppressed; permanent failures with bounce-type soft stay bounced but are not suppressed; code 621 (template not found) gets MAILGUN_TEMPLATE_NOT_FOUND and never suppresses. Temporary failures were already deferred without suppression. Also records the Mailgun live run (send path, live suite, webhook end to end through a cloudflared tunnel) and the CHANGELOG entry. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
github-actions Bot
pushed a commit
that referenced
this pull request
Nov 19, 2026
## [4.9.1](v4.9.0...v4.9.1) (2026-11-19) ### Bug Fixes * **mailgun:** refuse deleted Mailgun templates before sending; no suppression for ESP blocks ([#29](#29)) ([4ac0ba3](4ac0ba3)) ### Fixed * **Mailgun: a template deleted at Mailgun is no longer logged as sent.** Mailgun accepts a send that names a template it does not have (200 "Queued") and drops the message afterwards (event `failed`, delivery-status 621 "Template not found", retried every 10 minutes). Before a template send MagicMail now checks the template at Mailgun (`GET /v3/{domain}/templates/{name}?active=yes`, account-level templates `GET /v4/templates/{name}?active=yes`). A deleted template, or one without an active version, fails with `MAGIC_MAIL_PROVIDER_TEMPLATE_UNAVAILABLE` before any message is sent: another account that still has the template sends instead, else the configured Magic Mail fallback template, else the error is returned and the delivery log row is `failed`. A successful check is cached for 60 seconds per account and template (one extra request per template and minute for bulk sends, parallel sends share one check). If the check itself fails (network, timeout, 401/403, 429, 5xx), the send goes ahead and a warning is logged. * **Mailgun webhooks: ESP blocks and soft bounces no longer suppress the recipient.** A permanent failure with reason `espblock` (the recipient's provider refused the sender, for example `550 5.7.40`) is now recorded as **Blocked** and never added to the suppression list; Mailgun itself does not put such addresses on its bounce list. A permanent failure that Mailgun classifies as `bounce-type: soft` is still recorded as **Bounced** but not suppressed. Only permanent hard bounces suppress, as before. Template-not-found failures (code 621) get the reason code `MAILGUN_TEMPLATE_NOT_FOUND` (Deferred while Mailgun retries, Failed when final) and never suppress. ### Migration * Nothing to do. Mailgun template sends make one extra read request per template and minute; the API key needs read access to templates, which provider-template sync already requires. Addresses suppressed earlier because of a Mailgun `espblock` can be removed under **Plugin Settings → Bounces and recipient checks → Suppressed recipients** (source `mailgun`, reason code `MAILGUN_ESPBLOCK_*`).
This was referenced Nov 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two Mailgun fixes found and proven against the real Mailgun API (US sandbox domain, 2026-11-19). Full record:
docs/acceptance/2026-11-19-mailgun-live.md.1. Template sends: refuse a template that is gone at Mailgun (
fix(mailgun))Mailgun answers
200 Queuedfor a send that names a template it does not have, then drops the message (eventfailed,severity: temporary, delivery-status 621 "Template not found", retried every 600 s). 4.9.0 logged such mails as Sent.sendViaMailgun(template branch) now callscheckMailgunTemplate(server/src/utils/provider-api.js, reusesgetJson, 5 s timeout, fixed hosts):GET /v3/{domain}/templates/{name}?active=yes; account scope:GET /v4/templates/{name}?active=yes(the account-level get also takes the template name, per the Mailgun OpenAPI bundle)404or200withouttemplate.version(live: that is what Mailgun returns for a template without a version) →MAGIC_MAIL_PROVIDER_TEMPLATE_UNAVAILABLEbefore anymessagesrequest; tagged pre-dispatch (another account with the template may send) and fallback-safe (the configured local fallback template applies), log rowfailed2. Webhook: Mailgun
espblockand soft bounces no longer suppress the recipient (fix(webhooks))Task check result:
failed+temporary→ Deferred, never suppressed (correct already, now also tested with the live 621 shape).failed+permanent→ Bounced + suppressed: wrong for one live case. A real send was refused by the recipient's provider:permanent, reasonespblock,550 5.7.40,bounce-type: soft; Mailgun did not put the address on its own bounce list (GET /v3/{domain}/bounces/<addr>→ 404). 4.9.0 would have suppressed the address on every account. Now:espblock→ Blocked, never suppressedbounce-type: soft→ Bounced, not suppressedMAILGUN_TEMPLATE_NOT_FOUND(Deferred while temporary, Failed when permanent), never suppressedsuppress-*andoldunchangedLive results
LIVE_PROVIDERS=mailgun npm run test:liveonmain4.9.0200 Queued)MAGIC_MAIL_PROVIDER_TEMPLATE_UNAVAILABLE, nomessagesrequest, real check answered 404Webhook end to end (Strapi 5.63.0 + this branch's build, SQLite, filter proxy,
cloudflaredquick tunnel, domain webhooksdelivered/permanent_fail/temporary_failregistered viaPOST /v3/domains/{domain}/webhooks):temporary_fail(621) → 200, signature verified with the real signing key, log Deferred, no suppression; its Mailgun retry 10 min later, on the rebuilt host → 200, log reasonMAILGUN_TEMPLATE_NOT_FOUNDdelivered(test mode, code 650) → 200,deliveryConfirmedAtsetsignature→ 401; tamperedtoken→ 401; signature removed → 401failedGET /v3/domains/{domain}/webhooksandGET /v1/webhookssaved before the run; after deleting the three webhooks both responses are byte-identical. Tunnel and host stopped, host.env/DB deleted. Domain templates unchanged.espblock).Not proven live (spec/test only)
permanent_failwebhook delivery: Mailgun recorded theespblockfailure but nopermanent_failpost arrived within 10 min (temporary and delivered posts did). Mapping covered by tests with the observed shape. A hard bounce cannot be produced on a sandbox domain.old).Checks
npm run lint,npm run format:check: cleannpm test: 927 tests, 924 pass, 0 fail, 3 skipped (PostgreSQL multi-process tests withoutMAGIC_MAIL_TEST_PG_URL, as before);npm run test:admin: 20/20npm run build,npm run verify,npm run verify:runtime: pass;npm audit --omit=dev: 0 vulnerabilities; no dependency addedtests/mailgun-template-check.test.js(11, fake Mailgun server: missing, no active version, cache TTL, negatives not cached, in-flight sharing,/v4account scope, EU host, check failures do not block, fallback template, failover to another account, no check for plain sends);tests/webhook-outcomes.test.js"Mailgun severity and bounce type" (fails on 4.9.0)docs/delivery.md(mapping table and suppression rule),docs/sending.md,docs/live-webhook-checks.md(test mode does emitdeliveredwebhooks),docs/acceptance/2026-11-19-mailgun-live.md, CHANGELOG[Unreleased](Fixed + Migration)Release type: two
fix:commits → patch.🤖 Generated with Claude Code