How to Debug Mailgun Webhooks

Mailgun webhooks provide real-time notifications about email events including deliveries, bounces, complaints, opens, clicks, and unsubscribes. They are critical for monitoring email deliverability and engagement.

What are Mailgun Webhooks?

Mailgun webhooks are HTTP POST requests that Mailgun sends to your server when specific events occur in your account. Rather than continuously polling the Mailgun API for updates, webhooks deliver real-time notifications the moment something happens — a payment completes, a user signs up, a deployment finishes, or any other tracked event.

Debugging these webhooks can be challenging because they originate from Mailgun's servers, not your browser. You can't simply open DevTools to inspect them. That's where WebhookVault comes in — capture every Mailgun webhook, inspect the full payload and headers, and replay them to your local development server.

Common Mailgun Webhook Events

EventDescription
deliveredFired when an email is successfully delivered to the recipient's server
permanent_failFired when an email permanently bounces (invalid address, etc.)
openedFired when a recipient opens an email
complainedFired when a recipient marks an email as spam

Setting Up Mailgun Webhooks with WebhookVault

Follow these steps to start capturing and debugging Mailgun webhooks using WebhookVault.

1Create a WebhookVault endpoint

Sign up for a free WebhookVault API key and create an endpoint to capture Mailgun webhooks.

curl -X POST https://webhookvault.anethoth.com/api/v1/endpoints \
  -H "Authorization: Bearer wv_your_key" \
  -H "Content-Type: application/json" \
  -d '{"name": "Mailgun Webhooks"}'

# Response:
# {"url": "https://webhookvault.anethoth.com/hook/abc123", "inspect_url": "https://webhookvault.anethoth.com/inspect/abc123"}

2Configure Mailgun to send webhooks

Go to the Mailgun Dashboard > Sending > Webhooks Select the domain you want to configure webhooks for Click on the event type and enter your WebhookVault endpoint URL Save and test using Mailgun's 'Test Webhook' feature

3Inspect captured requests

Once Mailgun sends a webhook, you can inspect every detail through the WebhookVault API or web inspector.

curl https://webhookvault.anethoth.com/api/v1/endpoints/abc123/requests \
  -H "Authorization: Bearer wv_your_key"

# Returns all captured Mailgun webhook requests with full headers, body, and metadata

4Replay to your local server

Replay any captured Mailgun webhook to your local development server for testing.

curl -X POST https://webhookvault.anethoth.com/api/v1/endpoints/abc123/requests/1/replay \
  -H "Authorization: Bearer wv_your_key" \
  -H "Content-Type: application/json" \
  -d '{"url": "http://localhost:3000/webhook"}'

# The original Mailgun webhook is replayed to your local server

Sample Mailgun Webhook Payload

Here is an example of a typical Mailgun webhook payload. Use WebhookVault to capture real payloads from your Mailgun account for accurate testing.

{
  "signature": {
    "token": "abc123def456",
    "timestamp": "1706000000",
    "signature": "hmac_sha256_signature_here"
  },
  "event-data": {
    "event": "delivered",
    "timestamp": 1706000000,
    "recipient": "[email protected]",
    "message": {
      "headers": {
        "message-id": "abc123.mailgun.org",
        "subject": "Welcome to Our Service"
      }
    },
    "delivery-status": {
      "code": 250,
      "message": "OK"
    }
  }
}

Common Mailgun Webhook Issues

Here are the most common issues developers encounter when working with Mailgun webhooks, and how to resolve them.

Signature verification

Mailgun includes a signature object with token, timestamp, and HMAC-SHA256 signature. Verify using your Mailgun API key.

Legacy vs. new webhook format

Mailgun has legacy and current webhook formats. Ensure you're parsing the correct format based on your account settings.

Event routing

Different events can be routed to different webhook URLs. Configure each event type's URL separately in the dashboard.

Timestamp-based replay prevention

Check the timestamp in the signature to prevent replay attacks. Reject events older than a reasonable threshold.

Frequently Asked Questions

What are Mailgun webhooks?

Mailgun webhooks are HTTP callbacks that Mailgun sends to your server when specific events occur. Instead of polling the Mailgun API for changes, webhooks push real-time notifications to your application, making your integration more efficient and responsive.

How do I test Mailgun webhooks locally?

Use WebhookVault to capture Mailgun webhooks in the cloud, then replay them to your localhost. Create a WebhookVault endpoint, configure Mailgun to send webhooks to it, and use the replay API to forward captured requests to http://localhost:3000/webhook (or your local port).

How do I verify Mailgun webhook signatures?

Most webhook providers, including Mailgun, sign their webhook payloads to prove authenticity. Check the Mailgun documentation for the specific signature header and verification algorithm. Use WebhookVault to capture and inspect the raw headers to debug signature verification issues.

Why is WebhookVault better than ngrok for Mailgun webhook testing?

Unlike ngrok, WebhookVault captures and stores every webhook request with full headers and payloads. You can replay any Mailgun webhook to your local server as many times as needed, inspect historical requests, and share webhook data with your team. No tunnel to maintain or port to expose.

Start debugging Mailgun webhooks now

Create a free WebhookVault endpoint in seconds. Capture, inspect, and replay Mailgun webhooks with zero configuration.

Get Free API Key