Prompt
How do I handle bounced and complained addresses automatically?
Latest observation
To handle bounced and complained email addresses automatically, the standard approach is to use your email service provider’s event feedback and update your mailing list in real time.
1) Use bounce/complaint webhooks or event notifications
Most email platforms can send you events when:
- Hard bounce: address doesn’t exist, domain invalid, etc.
- Soft bounce: temporary issue like mailbox full
- Complaint: recipient marked your email as spam
Set up a webhook or event stream so your app is notified immediately.
2) Automatically suppress those addresses
When you receive an event:
- Hard bounce → mark the address as invalid and suppress it permanently
- Complaint → suppress immediately and permanently
- Soft bounce → retry a limited number of times, then suppress if it keeps failing
This means:
- do not send future campaigns to suppressed addresses
- keep a suppression list separate from your main list
3) Maintain recipient status in your database
Store a status field such as:
activebouncedcomplainedunsubscribedsuppressed
Update this status from webhook events automatically.
Example logic:
- bounce event with permanent failure →
suppressed - complaint event →
suppressed - soft bounce event count >= threshold →
suppressed
4) Process events idempotently
Email providers may send duplicate events, so make your handler safe to run multiple times:
- use the provider’s event ID
- ignore events you’ve already processed
5) Exclude suppressed addresses before sending
Before every send:
- filter out suppressed/bounced/complained addresses
- optionally also exclude recent soft bounces
6) Optional: keep audit logs
Log each event with:
- email address
- event type
- timestamp
- campaign/message ID
- provider event ID
This helps with debugging and compliance.
7) Compliance considerations
For complaints especially, suppressing immediately is important for deliverability and compliance. Also:
- honor unsubscribe requests
- don’t re-add complained users without explicit re-opt-in
- monitor complaint rates and bounce rates
Example workflow
- You send a campaign
- Provider delivers event notifications
- Your webhook receives a bounce/complaint
- Your app updates the user record to
suppressed - Future sends skip that address
Pseudocode example
def handle_email_event(event):
email = event["email"]
event_type = event["type"]
if event_type == "complaint":
suppress(email, reason="complaint")
elif event_type == "bounce":
if event["bounce_type"] == "hard":
suppress(email, reason="hard_bounce")
elif event["bounce_type"] == "soft":
increment_soft_bounce_count(email)
if get_soft_bounce_count(email) >= 3:
suppress(email, reason="too_many_soft_bounces")
If you want, I can show you how to implement this for a specific provider like SES, SendGrid, Mailgun, or Postmark.