When an email fails to deliver, the recipient server returns a Delivery Status Notification (DSN) email, commonly called a bounce. Parsing these bounces programmatically is vital to keep your subscriber list clean and maintain your domain reputation.
The Structure of a DSN Message
A DSN is a multi-part MIME email defined by RFC 3464. It contains three main sections: a human-readable summary of the failure, a machine-readable status block containing headers like Action: failed and Status: 5.1.1, and the original email headers.
Parsing the Status Codes
The status code (e.g., 5.1.1) is the key. The first digit indicates a permanent failure, while the remaining digits explain the specific issue (e.g., 1.1 means "User Unknown"). Your parser must read these codes, identify hard bounces, and automatically remove invalid addresses from your database.