How can I parse bounce messages automatically?

Still have a question, spotted an error, or have a better explanation or a source we should cite?

Bounce messages follow a standard format called Delivery Status Notifications (DSN). When a message can't be delivered, the receiving server returns a MIME-formatted report with two machine-readable parts: the classification code and the human-readable diagnostic message. Parsing these automatically is how you build reliable suppression logic.

The structure you're working with: a bounce message is a multipart/report MIME message. Inside, there's a message/delivery-status section that contains the actual status fields:

  • Status: a three-part code like 5.1.1. The first digit (5) means permanent failure. 4 means temporary. The rest classifies the failure type (address doesn't exist, mailbox full, etc.).
  • Diagnostic-Code: the human-readable error message from the server ("550 5.1.1 The email account that you tried to reach does not exist").
  • Final-Recipient: the address that failed.

How to implement parsing: use a MIME library for your language. In Python, the built-in email.parser handles this. In Node, mailparser works well. Extract the delivery-status section, read the Status field for classification, and run the Diagnostic-Code through pattern matching for finer classification (since different ISPs use different wording for the same failure type).

The practical reality for most senders: your ESP already does this and exposes classified bounce events via webhooks or API. SendGrid, Postmark, and most modern platforms send bounce webhook events with the type (hard/soft) already classified. Build your suppression logic off those events rather than raw MIME parsing unless you're running your own MTA.

If you are processing raw logs or need finer-grained classification than your ESP provides, the core pattern is: Status code first (5xx = permanent suppress, 4xx = retry), then diagnostic text matching for subcategories (hard bounce types like user unknown vs. domain not found vs. policy rejection each warrant different handling).

Contributors

Who worked on this answer

Every name links to their profile. Every company links to their site. Real people, real accountability.

Ask an AI · tailored to your setup

Design my bounce parsing system

I want to automate bounce handling for my sending infrastructure. Here's my situation: - Language/stack I'm working in: Python / Node.js / PHP / other - Whether I'm running my own MTA or using a third-party ESP: own MTA / ESP only / hybrid - My ESP (if applicable): e.g. SendGrid, Postmark, Mailchimp, custom - Whether my ESP sends bounce webhooks: yes / no / unsure - What I'm trying to classify: hard vs soft / specific failure subtypes / all of the above - How I'm currently handling bounces: manual / basic webhook / nothing yet - Specific bounce codes or messages I'm trying to understand: paste a few examples if you have them Help me design the right parsing approach for my setup, whether that's leveraging ESP webhooks or building raw DSN parsing.

Edit the yellow boxes, then send to the AI of your choice.