Prompt
How do I handle bounced emails automatically?
Latest observation
To handle bounced emails automatically, you typically set up bounce processing so your system can detect delivery failures and take action without manual review.
1) Use a dedicated sender and bounce address
If you send email through an ESP or SMTP server, make sure bounces go to a return-path / envelope-from address you control, such as:
bounces@yourdomain.commailer-daemon@yourdomain.com
This address receives DSNs (delivery status notifications) and non-delivery reports.
2) Parse bounce messages
Automatically inspect incoming bounce emails and classify them into:
-
Hard bounce: permanent failure
Examples: invalid address, domain doesn’t exist, user unknown- Action: suppress/remove the email address from future sends
-
Soft bounce: temporary failure
Examples: mailbox full, server unavailable, message too large- Action: retry later; after repeated failures, mark as invalid or inactive
Most bounce emails include status codes or text you can parse, such as:
5.x.x= permanent failure4.x.x= temporary failure
3) Update your database automatically
When a bounce is detected:
- mark the recipient as bounced
- store bounce reason/code
- increment bounce count
- suppress future sends based on your policy
Example policy:
- hard bounce → suppress immediately
- 3 soft bounces in 7 days → suppress temporarily
- complaint/unsubscribe → suppress permanently
4) Use an email provider’s webhook/API if possible
Many providers can do this for you automatically:
- Amazon SES → bounce/complaint notifications via SNS
- SendGrid → Event Webhook
- Mailgun → webhooks
- Postmark → bounce webhooks
- SparkPost → events webhooks
This is usually easier and more reliable than parsing raw bounce emails yourself.
5) Separate bounces from other mail
Use a dedicated mailbox or inbound processing route for bounce handling so normal inbox mail doesn’t get mixed in.
6) Handle complaints too
Bounces are only part of deliverability. Also handle:
- unsubscribe requests
- spam complaints
- blocked domains
- invalid syntax at signup
7) Recommended workflow
- Send email
- Receive bounce event or bounce email
- Extract recipient + status code + reason
- Classify hard/soft
- Update suppression list / customer record
- Retry only if soft bounce and retry policy allows
Example logic
550 5.1.1 User unknown→ hard bounce → suppress421 4.7.0 Temporarily deferred→ soft bounce → retry later552 Message size exceeds limit→ usually permanent for that message; may not mean the address is bad
Best practice
If you can, use your email provider’s bounce webhooks rather than building your own parser. It’s less error-prone and scales better.
If you want, I can show you:
- a sample bounce-processing architecture
- example code in Node.js / Python / PHP
- or how to do this with SES, SendGrid, or Mailgun