MailSlurp logo

mailgun email testing

Mailgun Email Testing: Verify Routes, Headers, Webhooks, and Inboxes

Test Mailgun email flows with MailSlurp inboxes, message assertions, header checks, route validation, webhook evidence, and deliverability diagnostics.

Mailgun email testing should prove the full message journey: the app action, the Mailgun send or route, the received inbox message, the headers, the links, the attachments, and the webhook evidence. MailSlurp gives teams controlled inboxes and APIs for testing those flows before customers depend on them.

Use this guide when your application sends transactional email through Mailgun, receives inbound email through Mailgun Routes, or compares Mailgun events with real inbox evidence during release checks.

Quick answer

Use MailSlurp with Mailgun when you need to:

  • create a fresh recipient inbox for each staging or CI run
  • send the real Mailgun template or API message to that inbox
  • wait for the received email without fixed sleeps
  • assert the subject, sender, body, links, OTP values, and attachments
  • inspect SPF, DKIM, DMARC, Return-Path, Message-ID, and Mailgun trace headers
  • compare Mailgun event webhooks with the message that actually arrived
  • test inbound route handling, reply capture, and webhook retries
  • run spam, blacklist, and inbox placement checks before important launches

Mailgun can send and route email. MailSlurp adds the controlled inbox and assertion layer that shows what arrived, how it was authenticated, and whether the user workflow is ready to ship.

When you want the test to run in code, create a MailSlurp test inbox and send the next Mailgun test message to that address.

Route the right Mailgun question

MailSlurp has several Mailgun-adjacent pages. Use this split:

  • Mailgun email testing explains how to test Mailgun sends, routes, headers, webhooks, and inbox receipt with MailSlurp.
  • Mailgun alternative covers the broader question of using MailSlurp for inbox APIs, inbound workflows, QA, and automation.
  • Mailgun alternatives helps teams compare provider options for testing and inbound email.
  • Mailgun vs SendGrid covers the send-provider shortlist.
  • Email API providers explains how Mailgun, SendGrid, Amazon SES, and MailSlurp fit into a broader email stack.

That keeps implementation testing separate from provider selection.

Mailgun test setup

A reliable Mailgun test run should use real messages and a controlled recipient:

  1. Create a MailSlurp inbox for the test case.
  2. Use the inbox address as the Mailgun recipient.
  3. Trigger the app action that sends through Mailgun, or send the exact Mailgun template through the Mailgun API.
  4. Wait for the message with a MailSlurp API wait helper.
  5. Assert the received subject, body, sender, links, attachments, and one-time codes.
  6. Inspect headers and authentication results.
  7. Compare the received message with Mailgun event webhook data.
  8. Store the MailSlurp message ID, Mailgun message ID, event state, and assertion result with the release record.

Avoid testing only with a shared personal mailbox. Shared inboxes hide state, filters, previous sender history, and timing issues that make failures hard to reproduce.

What to assert in a Mailgun email test

Start with the user-visible message. Then check the operational evidence.

Assertion What to check Why it matters
Subject Expected subject and template variables Catches broken template data before release
Sender From name, From address, reply address, and domain Catches identity drift and sender-domain mistakes
Body HTML and plain text contain the expected content Catches rendering, personalization, and fallback issues
Links Verify, reset, unsubscribe, and tracking links resolve Catches missing tokens, bad domains, and broken redirects
OTP Code exists, has the expected format, and expires correctly Catches auth-flow failures before users see them
Attachments File count, content type, filename, and size Catches invoice, report, and export regressions
Headers SPF, DKIM, DMARC, Return-Path, Message-ID, and Mailgun trace data Catches sender-auth and routing issues
Events Accepted, delivered, bounced, complained, or failed states Catches mismatches between provider events and inbox results

For implementation examples, use Email integration testing, Email testing API, and Email Sandbox.

Header and authentication checks

Mailgun can accept a message while the received email still exposes sender-auth or routing problems. Inspect headers after sender-domain changes, tracking-domain changes, template changes, or traffic-pattern changes.

Check:

  • SPF result for the envelope sender
  • DKIM signature domain and selector
  • DMARC alignment with the visible From domain
  • Return-Path and bounce-domain behavior
  • List-Unsubscribe and one-click unsubscribe headers for subscribed mail
  • Message-ID and provider trace headers used to correlate Mailgun events with inbox receipt

Use Email header analyzer, SPF checker, DKIM checker, and DMARC checker when the received message needs deeper review.

Mailgun Routes and inbound testing

Mailgun Routes can turn inbound email into webhook calls. That is useful, but the release test should still prove what was received and how downstream systems handled it.

Test inbound flows by checking:

  • the inbound address or route expression that should match the message
  • the raw message content and attachments
  • parsed sender, recipient, subject, and body fields
  • webhook signature validation
  • retry behavior when the receiver is unavailable
  • duplicate handling when the same inbound event is replayed
  • downstream action, such as support ticket creation, lead routing, or invoice extraction

MailSlurp can be the controlled sender or receiver in these tests. Use it to create a message, capture the resulting inbound email, and keep a stable message ID for debugging.

Webhook and event checks

Mailgun events and MailSlurp inbox evidence answer different questions. Use both when testing release-critical email.

Mailgun events can show whether Mailgun accepted, delivered, deferred, bounced, complained, failed, or routed a message. MailSlurp shows the received content, headers, attachments, and links that the test inbox actually saw.

Compare:

  • Mailgun message ID or event ID
  • MailSlurp received message ID
  • recipient address used for the test
  • template or sending path
  • final subject and sender
  • received timestamp
  • Mailgun event state
  • assertion result from the MailSlurp test

If Mailgun reports delivery but the MailSlurp inbox does not receive the message, treat the result as a route, filtering, placement, or address problem that needs review before release.

Bounce, block, and failure handling

Test failure paths deliberately. Do not wait for a production incident to learn how the workflow behaves.

Run checks for:

  • invalid recipient address
  • suppressed or bounced recipient
  • unverified or misconfigured sender domain
  • template with missing required variables
  • large attachment or unsupported file type
  • link domain or tracking-domain mistake
  • inbound route that matches the wrong recipient
  • webhook retry after receiver downtime
  • temporary provider deferral or delivery failure

Pair the Mailgun event state with MailSlurp inbox evidence so the team can tell whether the problem is submission, delivery, filtering, content, routing, or application handling.

Deliverability checks before launch

For customer-visible sends, add deliverability checks after content assertions pass.

Use MailSlurp to:

This matters when Mailgun sender authentication, link tracking, templates, inbound routes, or traffic volume changes. A successful send event does not prove inbox placement or workflow correctness.

CI workflow for Mailgun email testing

Use this sequence in CI or staging:

  1. Create a MailSlurp inbox for the test run.
  2. Trigger the app action that sends through Mailgun.
  3. Wait for the received email by recipient, subject, or sender.
  4. Extract and assert the OTP, magic link, invoice link, or confirmation URL.
  5. Inspect headers for sender-auth expectations.
  6. Compare the MailSlurp message ID with the Mailgun event ID when events are available.
  7. Fail the test if the message is missing, malformed, late, unauthenticated, or routed incorrectly.
  8. Keep the received message ID in the test output for debugging.

This turns Mailgun email into a testable product workflow instead of a manual inbox check.

FAQ

How do I test Mailgun emails before production?

Create a MailSlurp test inbox, send the Mailgun message to that inbox, wait for the received message, and assert the subject, body, links, OTP values, attachments, and headers.

Is a Mailgun delivered event enough?

No. A delivered event is useful, but release teams should still confirm inbox receipt, message content, sender-auth headers, and provider-placement behavior.

Can I test Mailgun Routes with MailSlurp?

Yes. Use MailSlurp as the controlled sender or receiver, trigger the Mailgun route, verify the webhook payload, and keep the MailSlurp message ID for debugging.

Can I test Mailgun OTP and password reset emails?

Yes. Use a MailSlurp inbox as the recipient, wait for the message, extract the OTP or reset link, and assert that the app accepts it.

Where should I compare Mailgun and MailSlurp?

Use Mailgun alternative for the broader provider question. Use this page when the job is testing Mailgun messages with real inbox and webhook evidence.