Prompt
I'm building a product that must handle bounce handling automatically
Latest observation
Understood — if your product needs to handle email bounces automatically, you’ll want a reliable bounce processing pipeline rather than trying to infer bounces from inboxes manually.
Here’s a practical blueprint:
1) Use a dedicated sending domain/provider
Send mail through a provider that supports:
- Bounce notifications / webhooks
- Complaint handling
- Delivery status notifications (DSNs)
Examples: SES, SendGrid, Mailgun, Postmark, SparkPost.
2) Separate address types
Maintain distinct addresses for:
- From: the visible sender
- Reply-To: where replies go
- Return-Path / Envelope-From: where bounces are sent
Bounces are usually delivered to the envelope sender (Return-Path), not the visible From: address.
3) Create unique per-message or per-tenant bounce identifiers
Include an identifier in the envelope sender, such as:
bounce+<message_id>@bounces.yourdomain.com- or provider-specific VERP/tagging
This lets you map a bounce back to:
- recipient
- campaign
- tenant/customer
- message type
4) Receive bounces automatically
Set up one of:
- Webhook-based bounce events from your ESP
- Inbound email processing for a bounce mailbox/domain
- DSN parsing if you run your own SMTP infrastructure
If you use a provider, webhook events are usually simplest and most accurate.
5) Classify bounces
Distinguish:
- Hard bounce: permanent failure, e.g.
user unknown,domain does not exist - Soft bounce: temporary failure, e.g.
mailbox full,server temporarily unavailable
Typical actions:
- Hard bounce → suppress address immediately
- Soft bounce → retry for a limited time, then suppress if persistent
6) Maintain suppression lists
Automatically suppress:
- hard bounces
- repeated soft bounces
- complaints/unsubscribes
This protects deliverability and reduces provider penalties.
7) Store bounce metadata
Keep fields like:
- recipient email
- provider message ID
- SMTP status code (
5.1.1,4.2.2, etc.) - diagnostic text
- bounce type
- timestamp
- source campaign/tenant
This is crucial for debugging and reporting.
8) Add idempotency and retries
Your bounce handler should be:
- idempotent: same event processed twice should not cause duplicate suppression
- durable: webhook failures should be retried
- auditable: preserve raw event payloads
9) Validate email upfront, but don’t rely on it
Do:
- syntax checks
- domain/MX checks
- optional verification at signup
But still treat bounces as the source of truth, because valid-looking emails can still bounce later.
10) Watch for edge cases
Handle:
- forwarded mail
- alias addresses
- vacation responders
- delayed DSNs
- DSNs with malformed or incomplete diagnostic text
- provider-specific event formats
Recommended architecture
A solid setup usually looks like:
- App sends email via ESP
- ESP sets unique return-path / tracking metadata
- ESP emits bounce webhook
- Bounce service ingests event
- Bounce service classifies bounce
- Suppression service updates recipient status
- Analytics/reporting stores event for later review
If you want the fastest path
If you’re starting from scratch, use:
- SES + SNS/Lambda or SendGrid webhooks or Mailgun events
- a dedicated bounce handler service
- a suppression table in your database
If you want, I can help you design:
- a bounce-handling architecture,
- a database schema, or
- sample code for a specific provider like SES, SendGrid, or Mailgun.