Prompt
How do I handle bounces and complaints automatically for transactional email?
Latest observation
To handle bounces and complaints automatically for transactional email, set up a feedback loop between your email provider and your sending system so your app can react immediately when delivery problems happen.
What to automate
You generally want to process these event types:
- Hard bounce: permanent failure, like invalid address
- Soft bounce: temporary failure, like mailbox full
- Complaint: recipient marked the email as spam
- Delivery/deferral: optional, useful for monitoring
Recommended workflow
1. Use an email service that emits events
Most transactional providers support webhook/event notifications, such as:
- Amazon SES
- SendGrid
- Mailgun
- Postmark
- SparkPost
Configure their event webhooks to send bounce/complaint events to your backend.
2. Include a stable recipient identifier
When sending email, attach metadata so you can map events back to the user or address:
- internal user ID
- message ID
- campaign/type
- recipient email
Example metadata:
{
"user_id": "12345",
"message_type": "password_reset",
"recipient": "alice@example.com"
}
3. Build a webhook endpoint
Your endpoint should:
- verify the provider signature
- parse the event
- log it
- update your database
- take enforcement action
Typical actions:
- add hard bounced addresses to a suppression list
- mark complaints as unsubscribed/blocked
- retry transient failures if appropriate
- stop sending to suppressed recipients
4. Maintain suppression lists
Have at least these lists:
- bounced_hard
- complained
- manual_blocked
- optionally soft_bounce_throttled
Before sending any transactional email, check suppression status.
5. Decide how to handle each event
A practical policy:
- Hard bounce: suppress immediately
- Complaint: suppress immediately, unless your compliance/legal policy requires otherwise
- Soft bounce: retry a limited number of times, then suppress or alert
- Unknown/blocked: inspect and decide case by case
6. Retry carefully
For transactional mail, retry only temporary failures:
- network issues
- rate limits
- mailbox full
- temporary ISP deferrals
Use:
- exponential backoff
- max retry count
- dead-letter queue for failures that persist
7. Track reputation and alerts
Monitor:
- bounce rate
- complaint rate
- deferral rate
- provider-specific rejection reasons
Send alerts if thresholds are exceeded.
Minimal architecture
- App sends email via provider
- Provider returns message ID
- Provider posts bounce/complaint events to your webhook
- Webhook updates suppression tables
- Sending service checks suppression before each send
Example decision logic
if event == hard_bounce:
suppress recipient
elif event == complaint:
suppress recipient immediately
elif event == soft_bounce:
increment retry counter
if retry_counter > limit:
suppress recipient
else:
log only
Important best practices
- Verify webhook authenticity
- Store raw event payloads for auditing
- Deduplicate events, since providers may resend them
- Make webhook processing idempotent
- Don’t send future transactional emails to complaint recipients
- Use a separate suppression policy for critical notices only if legally and operationally allowed
If you want a concrete implementation
I can provide:
- a sample webhook handler in Node.js, Python, or Go
- SES/SendGrid/Mailgun-specific setup steps
- a database schema for suppression tracking