Mailgun is a fine pick for WordPress transactional mail — competitive deliverability, an EU region for sites with data-residency requirements, and an API mature enough that the WordPress plugin layer is thin and reliable. The integration that breaks in production is rarely the API call itself; it’s the missing DKIM record, the over-scoped API key, or the absent bounce webhook that lets bounced addresses keep getting retried.
What’s happening
WordPress sends via Mailgun in one of two shapes:
- HTTP API — the recommended path. WP Mail SMTP and FluentSMTP both ship the Mailgun mailer; you paste the API key and the domain, and
wp_mail()becomes an HTTP POST toapi.mailgun.net/v3/<domain>/messages. - SMTP relay — Mailgun publishes credentials for the smtp.mailgun.org endpoint. Use this only if you cannot reach the HTTP API (corporate egress restrictions). The HTTP path is faster and has better retry semantics.
Mailgun requires three DNS records per sending domain: an SPF include, a DKIM TXT, and (recommended) a CNAME for tracking. The DKIM record is the one most operators copy wrong — Mailgun gives you a specific selector (e.g. mta._domainkey), and the value is multi-line. Copying it into a DNS UI that doesn’t handle the line continuation produces a broken signature that fails silently.
How to verify
dig +short TXT _spf.mailgun.org
dig +short TXT mta._domainkey.example.com
curl -s --user "api:$MAILGUN_API_KEY" \
"https://api.mailgun.net/v3/example.com/log?limit=10" | jq '.items[].event'
The Mailgun control panel’s “Domain Verification” page should show all green. A red on DKIM means the record didn’t propagate; a red on SPF means the include is missing or another sender clobbered it.
Test the WordPress end:
wp eval 'var_dump( wp_mail("you@example.com","sh-mailgun-test","body") );'
Then check the Mailgun logs for the event within 30 seconds. If WordPress returned true but Mailgun shows no event, the API call never reached Mailgun — re-check the API key scope.
The fix
- Create a sending API key scoped to the specific domain in the Mailgun dashboard — don’t use the account-wide master key. If the key leaks, the blast radius is one domain, not the whole account.
- Publish SPF, DKIM, and (recommended) the tracking CNAME exactly as Mailgun specifies. For DKIM, paste the raw value without adding quotes if your DNS UI auto-quotes.
- Configure the WordPress SMTP plugin with
mailgunas the mailer, the API key, the region (US or EU), and the domain. From Email must be on the verified domain. - Set up a bounce webhook. Mailgun fires HTTP callbacks on
bounced,complained,unsubscribed. Point them at a WordPress endpoint that updates the user’s record so the next signup or password-reset attempt doesn’t retry a known-bad address. - If this is a new sending domain on a Mailgun-shared IP, send a low volume for the first week and let the reputation build. If you bought a dedicated IP, run a warm-up schedule — 50 messages day one, 100 day two, doubling for two weeks.
- Configure the suppression list to auto-suppress hard bounces. Without it, the same bad address keeps eating reputation. Across an enterprise WordPress hosting fleet, the suppression list is synced back to WordPress so other sites also skip those addresses.
Stack Harbor deploys Mailgun across enterprise WordPress hosting sites with the DNS, the scoped key, the webhook handler, and the suppression sync wired together. If you have Mailgun configured but the bounce webhook isn’t doing anything, we can audit the loop.