Prompt
How do I add unsubscribe handling to transactional email systems?
Latest observation
To add unsubscribe handling to transactional email systems, the key is to distinguish between required service messages and optional marketing/promotional messages.
1) Separate transactional from marketing
Only allow unsubscribe for emails that are truly optional, such as:
- product updates
- feature announcements
- tips/newsletters
- upsell campaigns
For emails that are essential to the service, you generally should not suppress them, because they’re needed to fulfill the contract or provide the product:
- password resets
- receipts/invoices
- security alerts
- account verification
- shipping notifications
- legal notices
2) Add a subscription preference model
Use a preference system instead of a single global unsubscribe flag.
Typical fields:
email_opt_in_marketingemail_opt_in_product_updatesemail_opt_out_all_non_essentialsuppression_reasonunsubscribed_at
This lets users opt out of one category without blocking necessary transactional messages.
3) Include unsubscribe links where appropriate
For non-essential transactional-adjacent emails, include:
- a visible unsubscribe link
- a preference center link
- a one-click unsubscribe mechanism if possible
In email headers, also support:
List-UnsubscribeList-Unsubscribe-Post: List-Unsubscribe=One-Click
Example headers:
List-Unsubscribe: <https://example.com/unsubscribe?token=abc123>
List-Unsubscribe-Post: List-Unsubscribe=One-Click
4) Build a preference center
Create a page where users can:
- unsubscribe from all non-essential emails
- choose categories
- re-subscribe later
- see what each category means
This is better than forcing users into an all-or-nothing choice.
5) Enforce suppression at send time
Before sending any email, check:
- email type
- user preferences
- suppression list
- legal/required delivery rules
Pseudocode:
if email.type in ESSENTIAL_TYPES:
send(email)
elif user.has_unsubscribed(email.category):
skip_send()
else:
send(email)
6) Maintain a suppression list
Store unsubscribed recipients in a durable suppression system so they don’t get re-added accidentally.
Include:
- email address
- category
- timestamp
- source of unsubscribe
- IP/user agent if needed for audit
7) Handle email provider webhooks
If you use an ESP like SendGrid, SES, Postmark, Mailgun, etc., process:
- unsubscribe events
- spam complaints
- bounces
Then sync those back into your system to prevent future sends.
8) Be careful with compliance
Depending on region and email type, laws like CAN-SPAM, GDPR, ePrivacy, or CASL may apply. Common best practices:
- honor unsubscribe quickly
- make it easy and free
- don’t require login for unsubscribe
- don’t send marketing after opt-out
- keep proof of consent where required
9) Good UX pattern
A common approach is:
- essential transactional emails: no unsubscribe, but may include a link to manage email preferences
- optional transactional/product emails: unsubscribe link + preference center
- all marketing emails: one-click unsubscribe
10) Recommended architecture
A solid setup usually has:
- Email classification
- Preference store
- Suppression list
- Send-time policy check
- ESP webhook ingestion
- Preference center UI
If you want, I can also give you:
- a database schema for unsubscribe handling
- sample API endpoints
- example code in Node/Python/Ruby
- guidance for a specific ESP like SendGrid or SES