Skip to content

The moment it happens

Get a message when an email permanently fails

Each hard failure or spam complaint shows up with the recipient and reason, so you can follow up.

Runs
The moment it happens
Apps
Mailgun
AI
Not needed
Access
private API key to register webhook

Send this to your assistant

Create a ClickRuntime automation: when Mailgun reports a permanent failure or a spam complaint, post the recipient, subject and reason to #email-ops in Slack.

Paste it into your assistant. It tells you what it will send or change before it runs live.

First time? Adding ClickRuntime to your assistant takes about two minutes.

Why use it

Why teams use this automation

A new customer signs up, never gets the verification email and quietly leaves. An invoice to your biggest account bounces because their finance contact left the company, and nobody notices until the payment is late. When Mailgun cannot deliver a message permanently, the failure is recorded in logs that no one reads, and the person who needed that email has no idea it never arrived.

Mailgun can call ClickRuntime as soon as a message fails permanently. The call is verified using Mailgun's signature, so only genuine events are accepted, and a message goes to your channel naming the recipient and the reason for the failure. It reacts immediately, with no polling.

It is most valuable for transactional email such as invoices, onboarding and password resets, where one undelivered message has a real cost.

What you get out of it

  • Lost customers are noticed in time

    A person who never received the welcome email can still be rescued if support hears about it within the hour. They can call, correct the address or send the message from another channel.

  • Late payments are avoided

    When an invoice bounces, finance can contact the customer by phone the same day. Without the alert, the invoice may sit undelivered for weeks and the payment slips past its due date.

  • Typos in addresses get fixed

    Many permanent failures come from a mistyped domain such as gmial.com. Seeing them as they happen lets you correct the record and resend, rather than leaving a user locked out.

  • Only genuine events trigger a message

    Checking Mailgun's signature means a fake request cannot post to your channel. You can trust that every notification reflects a real delivery problem. Fake requests are simply rejected, so the channel only shows events that came from Mailgun itself.

  • Suppression lists stay healthy

    Knowing which addresses fail permanently helps you remove or fix them, keeping your bounce rate low. That protects the reputation of your sending domain for the messages that matter. Cleaner lists also mean fewer wasted sends over time.

  • Support gets context before the call

    When a customer writes in to say an email never arrived, support can search the channel and see the exact error. That turns a vague complaint into a concrete fix.

How it works

What happens, step by step

  1. Each time Mailgun records a hard failure or a spam complaint, it tells ClickRuntime straight away.

  2. The automation checks the message really came from Mailgun.

  3. A message goes to #email-ops with the recipient, the email's subject and the reason, so you can follow up.

Before it runs live

  • Connect Mailgun
  • Paste your automation's link into the other app's webhook settings

What you get

RunsThe moment it happens
Get a message when an email permanently failsjust nowSucceeded
Slack · #email-opsMailgun failed: pat@northwind.example Subject: Your Acme receipt Reason: 550 5.1.1 mailbox does not exist

Build your own

Need it to work differently?

This template is a starting point. Copy the prompt and change it, or describe a different automation from scratch, with your own conditions, more apps or an AI step. Your assistant writes it, tests it and runs it on ClickRuntime.
  • Your own rules

    Conditions, thresholds, filters and exceptions, written the way you'd explain them to a colleague.

  • Any number of apps

    One automation can read from one app and update several others. Over 248 apps are ready, and anything with an API works too.

  • AI where it helps

    Summaries, classification, extraction and drafts use ClickRuntime's built-in AI, with no extra key.

  • On a schedule or on each event

    Runs as often as every 5 minutes, or the moment an app sends an event, and keeps track of what it already handled.

Changes you can ask for

  • Act only on the items that match your own rules, and skip the rest
  • Add an AI step, for example to summarize, sort or draft a reply
  • Add another app, for example also send it to Slack
  • Combine it with other Mailgun steps into one automation

Under the hood

The code that runs this automation

This is the Python script that runs each time the automation starts. Your AI assistant writes it for you when you send the prompt, and you allow each step in your assistant. To change how the automation works, describe the change to your assistant and it updates the script for you. For every function it can use, see the script reference.
permanent_failure_notifications.pyexample
import hashlib, hmac
from clickruntime import on_event, credentials, notify

@on_event
def handle(event):
    body = event.json or {}
    sig = body.get("signature", {})
    expected = hmac.new(credentials.secret("MAILGUN_WEBHOOK_SIGNING_KEY").encode(),
                        f"{sig.get('timestamp')}{sig.get('token')}".encode(), hashlib.sha256).hexdigest()
    if not hmac.compare_digest(expected, sig.get("signature", "")):
        return {"rejected": "bad signature"}
    data = body["event-data"]
    if not (data["event"] == "complained" or (data["event"] == "failed" and data.get("severity") == "permanent")):
        return {"skipped": data["event"]}
    subject = data.get("message", {}).get("headers", {}).get("subject", "(no subject)")
    reason = data.get("delivery-status", {}).get("description") or data.get("reason") or data["event"]
    notify.slack(f"Mailgun {data['event']}: {data['recipient']}\nSubject: {subject}\nReason: {reason}",
                 channel="#email-ops")
    return {"posted": True}

FAQ

Common questions

What counts as a permanent failure in Mailgun?
A permanent failure, also called a hard bounce, means the receiving server rejected the message in a way that will not improve, such as a non-existent mailbox. Temporary issues like a full inbox are retried by Mailgun and are not included.
Can I get alerts only for important emails?
Yes. Messages can be filtered by tag, sender address or recipient domain, so an invoice or onboarding message triggers an alert while newsletter bounces are ignored. Describe the rule to your AI assistant and approve it.
What does the alert tell me about the failure?
It names the recipient address and includes the error description Mailgun supplies, such as an unknown user. That is usually enough to decide whether to correct the address, contact the person another way, or ignore it.
What permissions does it need?
private API key to register webhook. Nothing else in your accounts is used.
Does it need AI?
No. It runs without AI, so it doesn't use your plan's AI allowance.
How many runs does it use?
One run for each event the app sends.
Can I change how it works?
Yes. Describe the change to your AI assistant, for example a different schedule, channel or filter. It updates the automation, tests it and tells you what changed.

Set up “Get a message when an email permanently fails” from your assistant

Copy the prompt above, or connect your assistant first. Free plan, no credit card.