Skip to content

Deliverability

Mailgun setup: API key, domains and webhooks

Mailgun setup with Inspiremail: connect a private API key in the right region, add webhooks per sending domain and save the signing key to verify events.

· Last updated · 5 min read · By

Mailgun setup: API key, domains and webhooks

TL;DR: connect Mailgun by pasting a private API key in Integrations › Mailgun › Connect account, choosing the US or EU region your Mailgun account lives in. Then add webhooks for each sending domain in Mailgun with the URL Inspiremail shows, and paste Mailgun's HTTP webhook signing key into the account. Verified domains become senders on Deploy, and failures and complaints suppress automatically.

A sending domain is the domain Mailgun signs and sends for, such as mg.example.com, with its own DNS records and webhooks. The webhook signing key is the account-wide secret Mailgun uses to sign every webhook call.

The region is the one setting people get wrong. A US key against the EU endpoint, or the other way round, simply fails.

What you need from Mailgun

  • A verified sending domain with its SPF and DKIM records in place. Mailgun's getting started guide walks through adding one.
  • A private API key (Settings › API Security › Add new key).
  • The HTTP webhook signing key, on the same API Security page. Mailgun's page on securing webhooks explains that this key signs every webhook call and isn't the same as the API key.
  • Which region the account was created in: US or EU.

Step 1: connect the account

  1. Open Integrations › Mailgun and click Connect account.
  2. Paste the private API key.
  3. Optional: enter one Sending domain (for example mg.example.com). It's checked against the account's domains; leave it empty to use every verified domain.
  4. Choose the Region: US (api.mailgun.net) or EU (api.eu.mailgun.net).
  5. Optionally name the account, then click Test & connect.
Connect Mailgun dialog in Inspiremail with a private API key field, an optional sending domain field, a Region select set to US (api.mailgun.net) and an optional account name

The Connect Mailgun dialog: key, optional domain, region and name.

Step 2: add the webhooks in Mailgun

Open the account's Event webhook section in Inspiremail. It lists the URL, the steps for your region and the event names.

  1. In Mailgun open Send › Sending › Webhooks and pick the sending domain.
  2. Click Add webhook for each event type: Delivered Messages, Permanent Failure, Temporary Failure, Spam Complaints and Unsubscribes. Paste the webhook URL exactly. Opens and Clicks are optional, because Inspiremail tracks those on your own tracking domain.
  3. Repeat for every sending domain of the account.
  4. Copy the HTTP webhook signing key from Settings › API Security and paste it in Inspiremail, then Save. Events are refused until it's saved.
  5. Use Test webhook on one of the webhooks in Mailgun. The account's last event time updates within a minute.
Mailgun EU account page in Inspiremail showing the verified domain mg.example.net and the Event webhook panel with the webhook URL, the five Mailgun steps, the events to send and the saved HTTP webhook signing key

A connected Mailgun account (fictitious demo data) with the webhook steps for its region.

What Inspiremail does after setup

  • Domains as senders. Each verified domain becomes a sender on Deploy. On Deploy you pick the local part (hello@, deals@) and the domain identity supplies the rest.
  • Raw MIME. Messages go out through Mailgun's messages.mime endpoint as the full message Inspiremail built, so headers such as List-Unsubscribe, Message-ID and your own X- headers arrive untouched. Mailgun's own tracking is switched off.
  • Verified events. Each webhook call is checked with HMAC-SHA256 over the timestamp and token using your signing key. Permanent failures and complaints go to suppression; deliveries and temporary failures feed the live monitor, reports and auto-pause. Attribution travels as Mailgun user variables, so every event maps back to its drop.
  • Pacing. The account starts at 50 emails per second, which you can change on the account.

Why it's quick

You paste one key and one signing key. The webhook panel already knows your region and lists your domains, so the console steps are specific to your account. Send test event signs a synthetic event with the saved key and runs it through the real verification code, which tells you right away whether the key you pasted is the right one.

Before your first Mailgun drop

  1. Don't send from the sandbox domain. Mailgun's sandbox only delivers to authorized recipients, so a real list fails with a 403. Add and verify your own domain first.
  2. Check every domain has all five webhooks. It's easy to set them up on one domain and forget the second.
  3. Save the signing key and test it with Send test event. If that fails, nothing from Mailgun will be accepted.
  4. Add a tracking domain per Mailgun domain and send a small seed drop before the real one.

When something goes wrong during a drop

What Mailgun returnsWhat Inspiremail does
HTTP 429Not counted as failed. The message goes back in the queue, sending pauses for two seconds, and the next pass sends it. The live monitor shows "Provider throttling; retrying shortly".
HTTP 402, or a quota / limit messageLogged as a quota failure with Mailgun's code. Check your plan's limits in Mailgun.
HTTP 401Owners and managers get a critical "Provider credentials rejected" alert.
HTTP 403 mentioning sandbox or authorized recipientsRejected. You're sending from a sandbox domain or an unverified one.
HTTP 404Rejected. Usually the domain was removed from Mailgun after you connected. Click Refresh.

Deliverability problems show up in the events rather than the API answers. By default a drop pauses itself if bounces pass 5% or complaints pass 0.1% once 500 messages are delivered, and both thresholds can be changed per drop. Mailgun's sending API reference lists the other error responses.

Troubleshooting

  • "Enter a Mailgun API key": the field is empty, too short or contains spaces.
  • Test & connect fails with "Mailgun 401: …": usually the wrong region, or a sending key pasted instead of the account's private API key.
  • A domain is missing from the identities: it isn't verified in Mailgun yet, or the optional Sending domain limits the account to another domain. Verify it and click Refresh.
  • Mailgun shows the webhook failing with HTTP 401 "Invalid signature": the signing key saved in Inspiremail isn't the account's current HTTP webhook signing key. Copy it again (it changes if someone rotates it).
  • Events from one domain only: the webhooks were added to a single domain. Repeat step 2 for the others.

How we checked this guide

We tested each step in a demo organization with fictitious data on 22 November 2026 and compared it with the provider documentation linked above, and with NIST SP 800-177 Rev. 1, Trustworthy Email for the background on SPF and DKIM. Screens, button labels, limits and error messages are taken from the product as it works today. If something here no longer matches what you see, contact us and we'll correct it, as our editorial policy describes. Read more about us.

Give each Mailgun domain a tracking domain and a warmup plan if it's new. Comparing providers? See the guides for SendGrid, SparkPost and Amazon SES. Overview: Mailgun integration and multi-provider sending.

Frequently asked questions

Which Mailgun key does Inspiremail need?

A private API key from Settings › API Security. Pick the region the Mailgun account was created in: US (api.mailgun.net) or EU (api.eu.mailgun.net).

Do I have to add the webhooks for every Mailgun domain?

Yes. Mailgun webhooks are configured per sending domain, so repeat the webhook setup for each domain you send from. The webhook URL and the signing key are the same for all of them.

Where is the Mailgun webhook signing key?

In the Mailgun control panel under Settings › API Security › HTTP webhook signing key. It is account-wide and different from your API key.

Can I limit Inspiremail to one Mailgun domain?

Yes. Fill in the optional Sending domain when you connect; it is checked against the account's domains. Leave it empty to use every verified domain of the account.

Does Inspiremail keep my custom headers with Mailgun?

Yes. Messages go to Mailgun as complete raw MIME through the messages.mime endpoint, so every header and MIME option set on Deploy is kept.

  • Mailgun setup
  • mailgun
  • webhooks
  • signing key
  • integration guide

Product updates and deliverability notes

One email when something worth knowing ships — new features, provider changes and bulk-sender rule updates. No spam, unsubscribe anytime.

Ready to run your next drop on Inspiremail?

Tell us about your volume, providers and networks — or apply directly and pick your plan during onboarding.

Already a customer? Sign in