Sending

Connect Mailgun

Mailgun is a developer-friendly transactional email API. Two fields: your sending domain and an API key.

Overview

Mailgun organizes sending around domains. Every send is associated with a Mailgun domain, and the domain determines which DNS records Mailgun expects. Mailgun has two regional infrastructures: US (default) and EU. The EU region keeps data within Europe — use it if your recipients or your own data residency requirements demand it.

US vs EU — PICK CORRECTLY

If your domain was added in the Mailgun EU region, you must set region to euin Nudgel. Using the wrong region causes authentication errors even with a valid API key. The two regions have separate API endpoints (api.mailgun.net vs api.eu.mailgun.net).

Get your credentials

  1. Log in to app.mailgun.com
  2. Go to Sending → Domains and confirm your sending domain is verified (or add a new one and follow the DNS instructions)
  3. Go to Settings → API Keys
  4. Create a new Sending API Key (not the Private API Key — that has broader permissions than you need)
  5. Note which region your domain lives in (visible on the domain list page)

Add the provider in Nudgel

  1. Go to Settings → Providers
  2. Click Add a provider
  3. Pick Mailgun
  4. Fill in the fields:
FieldRequiredNotes
domainYesYour Mailgun sending domain, e.g. mail.acme.co.ke. Must match the domain in your Mailgun account.
from_emailYesMust be something@<your_mailgun_domain>
from_nameYesDisplay name shown to recipients
regionYesus or eu. Match the region where your domain was created in Mailgun.
api_keyYesMailgun Sending API Key. Encrypted at rest.

Test the connection

curl
curl -X POST https://api-raven-cloud.autotribes.app/v1/messages \
  -H "X-Raven-Key: rk_live_a3f7b2c1_..." \
  -H "Content-Type: application/json" \
  -d '{
    "channel": "email",
    "to": "you@example.com",
    "from": "noreply@mail.acme.co.ke",
    "subject": "Nudgel test — Mailgun",
    "bodyHtml": "<p>If you can read this, Mailgun is wired up.</p>",
    "bodyText": "If you can read this, Mailgun is wired up."
  }'

Check Mailgun → Logs (under your domain) to confirm the message was accepted.

Set up webhooks

Configure webhooks in Mailgun → Sending → Webhooks. You can set different URLs per event type, but the simplest setup is one URL for all events.

Set the URL to:

text
https://api-raven-cloud.autotribes.app/v1/webhooks/email/mailgun/{YOUR_TENANT_ID}

Enable: Delivered, Permanent failure (hard bounce), Complained (spam), Unsubscribed. Hard bounces and spam complaints auto-add to your suppression list. See the webhooks guide.

Verify your sending domain at Mailgun

To send from your own domain (e.g. mail.example.co.ke) through Mailgun, publish DKIM records Mailgun generates for you. Nudgel orchestrates this from one dashboard.

  1. In Nudgel dashboard, go to Settings → Sending domains → Add domain, enter your domain.
  2. On the next screen, select Mailgun. Nudgel calls Mailgun's domain registration API using your credentials and shows you the DNS records to publish.
  3. Publish the records at your DNS host (Cloudflare, Route 53, etc.).
  4. Nudgel polls every 30 seconds for the first 10 minutes, then hourly. Verification surfaces in the dashboard automatically.

Add this to your SPF record

Append include:mailgun.org to your existing SPF record (or create a new v=spf1 include:mailgun.org -allif you don't have one).

Mailgun-specific notes

  • US and EU regions are independent — always verify the domain in the region matching your Nudgel provider config. A domain verified in EU is not visible from the US API.
  • Mailgun returns three record types for a verified domain: a DKIM TXT, an SPF TXT, and a tracking CNAME. Publish all three.

Full setup walkthrough: Sending domains setup

Troubleshooting

SymptomMost likely cause
failed — "Forbidden" / 403API key is wrong, or you set the wrong region. A US key does not work against the EU endpoint and vice versa.
failed — "Domain not found"The domain field does not match a domain in your Mailgun account. Check spelling and region.
failed — "From address does not match domain"The from_email domain must match the Mailgun domain you configured.
failed — "Domain is unverified"Your Mailgun domain has not passed DNS verification. Check the DNS records in Mailgun → Sending → Domains → [domain] → DNS records.
Emails land in spamEnsure your Mailgun domain is fully verified (all DNS records green). See sending domains.