Sub topic 11
Suppression lists and checking them before every send
This chapter assumes you have read the earlier chapters on the subscriber lifecycle and the unsubscribe flow. It also assumes you know basic SQL and one programming language.
What a suppression list is
A suppression list is a set of addresses you must never email, whatever the rest of your data says. It is separate from subscribers.status for a reason. A status can be overwritten by a CSV import, a re-signup form, or a bug. A suppression entry is an independent safety net that does not depend on those paths being correct.
It also covers addresses that were never confirmed subscribers, such as an address that hard-bounced during a transactional send.
What belongs on it
| Reason | Added when | Can it be removed? |
|---|---|---|
| `unsubscribed` | The person unsubscribes | Only after a fresh, confirmed opt-in |
| `hard_bounce` | The receiving server reports a permanent failure | Normally no |
| `complaint` | A mailbox provider reports a spam complaint | Normally no |
| `manual` | Support or legal staff add it on request | Staff only |
A minimal schema
CREATE TABLE suppressions (
email TEXT PRIMARY KEY,
reason TEXT NOT NULL
CHECK (reason IN ('unsubscribed', 'hard_bounce', 'complaint', 'manual')),
source TEXT NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);Store the address in lower case, and lower-case it again before every lookup. Otherwise [email protected] slips past an entry for [email protected]. Do not strip +tag parts. Many providers treat them as distinct addresses, and collapsing them could suppress the wrong person.
Checking before every send
Run the check in the last step before a message is handed to your mail server, not when the campaign is built. Someone can unsubscribe between scheduling and sending, and the check must see that.
def filter_suppressed(db, emails):
"""Return only the addresses that are not suppressed.
Raises if the lookup fails, so the caller sends nothing.
"""
normalised = [e.strip().lower() for e in emails]
rows = db.execute(
"SELECT email FROM suppressions WHERE email = ANY(%s)",
(normalised,),
).fetchall()
blocked = {row[0] for row in rows}
return [e for e in normalised if e not in blocked]The function fails closed. If the database is unreachable, the exception stops the batch. Sending to a possibly suppressed address is worse than a delayed campaign.
Keeping the list trustworthy
- Write the suppression row in the same transaction that sets the status to
unsubscribed. If one succeeds and the other fails, the two will disagree. - Never delete a subscriber's row when they unsubscribe. Deleting it also deletes the evidence of why you stopped.
- Route imports through the same filter. A purchased or migrated file is the most common way suppressed people get mailed again.
- Feed bounce and complaint events from your mail provider into the table automatically, because manual updates fall behind.
Exercise
A campaign was scheduled on Monday for 1,000 confirmed subscribers and sent on Wednesday. One person unsubscribed on Tuesday. Why does checking the suppression list at scheduling time fail to protect them, and where should the check run?
Show answer
The Monday check could not know about Tuesday's unsubscribe, so the person would still be mailed. The check must run at send time, in the last step before the message goes to the mail server, and it should fail closed if the lookup errors.