Dev Ops · n8n

Instantly Alert Your Team on Slack When Mailgun Detects an Email Bounce

Listens for permanent bounce events from Mailgun via webhook and forwards a formatted alert to a Slack channel in real time. Email admins get immediate visibility into delivery failures without manually checking logs.

difficulty Beginnersetup 30 minresult A Slack message is automatically sent to your chosen channel every time Mailgun reports a permanent bounce, including the recipient address, error code, and timestamp.
  1. 1

    Create a Webhook trigger to receive Mailgun bounce events

    Add a Webhook node as the trigger. Set HTTP Method to POST and copy the generated webhook URL. In your Mailgun dashboard under Sending > Webhooks, paste this URL for the permanent_fail event type. This node captures the raw bounce payload from Mailgun.

  2. 2

    Filter for permanent bounce events only

    Add an IF node connected to the Webhook. Set the condition to check that {{$json.body['event-data'].event}} equals the string failed. This ensures only hard bounces pass through and soft transient errors are ignored.

  3. 3

    Extract and format bounce details

    Add a Set node after the IF true branch. Create three fields: recipient mapped to {{$json.body['event-data'].recipient}}, errorCode mapped to {{$json.body['event-data']['delivery-status'].code}}, and timestamp mapped to {{$json.body['event-data'].timestamp}}. This shapes the data for a clean Slack message.

  4. 4

    Send the formatted alert to Slack

    Add a Slack node connected to the Set node. Under Resource choose Message and under Operation choose Send. Set Channel to your target channel (e.g. #email-alerts). Set Text to :warning: *Email Bounce Detected* • *Recipient:* {{$json.recipient}} • *Error Code:* {{$json.errorCode}} • *Time:* {{$json.timestamp}}. Add your Slack OAuth credential in the node credentials section.

Frequently asked questions

How do I authenticate n8n with Slack?

In n8n, go to Credentials and create a new Slack credential using OAuth2. You will need to create a Slack App in the Slack API portal, grant it the `chat:write` scope, and complete the OAuth flow. The credential then appears in the Slack node dropdown.

What if my Mailgun payload structure is slightly different?

Mailgun webhook payloads can vary slightly by plan or region. Send a test bounce from Mailgun, then inspect the raw JSON in the n8n Webhook node execution log. Adjust the field paths in the Set node (Step 3) to match the exact keys you see in your payload.

Can I also capture soft bounces or spam complaints?

Yes. In your Mailgun dashboard, add additional webhook URLs for `temporary_fail` or `complained` events pointing to the same n8n webhook URL. Then update the IF node condition to also allow those event values, or remove the filter entirely to handle all event types in one workflow.

About this recipe. Recipes on FlowRecipesHub are written for business owners, not developers, and are tested before publishing — how recipes get made. Some ingredient links are affiliate links that cost you nothing — full disclosure.