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.
- 1
Create a Webhook trigger to receive Mailgun bounce events
Add a
Webhooknode as the trigger. SetHTTP Methodto POST and copy the generated webhook URL. In your Mailgun dashboard under Sending > Webhooks, paste this URL for thepermanent_failevent type. This node captures the raw bounce payload from Mailgun. - 2
Filter for permanent bounce events only
Add an
IFnode connected to the Webhook. Set the condition to check that{{$json.body['event-data'].event}}equals the stringfailed. This ensures only hard bounces pass through and soft transient errors are ignored. - 3
Extract and format bounce details
Add a
Setnode after the IF true branch. Create three fields:recipientmapped to{{$json.body['event-data'].recipient}},errorCodemapped to{{$json.body['event-data']['delivery-status'].code}}, andtimestampmapped to{{$json.body['event-data'].timestamp}}. This shapes the data for a clean Slack message. - 4
Send the formatted alert to Slack
Add a
Slacknode connected to the Set node. UnderResourcechoose Message and underOperationchoose Send. SetChannelto your target channel (e.g.#email-alerts). SetTextto: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.