Sub topic 11
Suppression Lists and Checking Them Before Every Send
This chapter assumes you have read the chapters on the subscriber lifecycle and the unsubscribe flow. You should be comfortable with basic SQL, one general-purpose programming language, and the idea that mailbox providers judge a sender by complaints and bounces.
What a suppression list is
A suppression list is a set of addresses that must never receive marketing email from you, whatever else your data says. The subscriber table says who you may mail. The suppression list says who you must not mail, and it wins every disagreement.
The two are separate on purpose. A subscriber row can be edited, imported over, restored from a backup, or recreated when someone signs up again. A suppression entry is a durable fact about an address. If it lives only as a status value on the subscriber row, a careless import can overwrite it.
Addresses typically end up on the list for these reasons:
| Reason | Trigger | Should the address ever return? |
|---|---|---|
| `unsubscribe` | The person opted out | Only after a fresh, deliberate opt-in |
| `complaint` | The person marked a message as spam, reported through a feedback loop | Treat as permanent |
| `hard_bounce` | The mailbox does not exist or the domain rejects mail permanently | Rarely, and only if the address is verified again |
| `soft_bounce_limit` | Repeated temporary failures such as a full mailbox | After a cool-down, if the person re-confirms |
| `manual` | Support or legal request, erasure follow-up | Case by case |
| `role_or_trap` | Known spam trap or role address you decided to exclude | No |
Why a separate list is worth having
Three situations show why.
- Re-import. Someone unsubscribes in March. In June the sales team uploads a spreadsheet that contains the same address. A plain upsert would set the status back to
confirmed. With a suppression check, the upload is blocked or the address is skipped. - Erasure requests. If a person asks you to delete their data, you may still need to remember that you must not mail them. Keeping a hashed copy of the address in the suppression list lets you do that without keeping the full profile.
- Several lists or products. One person may be in many lists. A global suppression list applies across all of them, while a per-list opt-out applies to one.
Scope: global or per list
Decide the scope of each entry when you create it.
- Global entries apply to every send. Use them for complaints, hard bounces, and requests such as "stop emailing me".
- Scoped entries apply to one list or topic. Use them when someone leaves "events" but still wants "weekly digest". This is the preference centre case from later chapters.
Transactional email, such as a password reset the person requested, is usually outside marketing suppression. Hard bounces and complaints still matter for transactional mail, because sending to a dead mailbox harms your reputation. Define in your own policy which reasons block which message classes, and write that policy down.
A schema
Store the address in a normalised form so that [email protected] and [email protected] match. Lowercasing the whole address is the common practical choice, even though the local part is technically case-sensitive.
CREATE TABLE suppressions (
id BIGSERIAL PRIMARY KEY,
email_norm TEXT NOT NULL,
scope TEXT NOT NULL DEFAULT 'global',
reason TEXT NOT NULL
CHECK (reason IN ('unsubscribe', 'complaint', 'hard_bounce',
'soft_bounce_limit', 'manual')),
source TEXT NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
expires_at TIMESTAMPTZ,
UNIQUE (email_norm, scope, reason)
);
CREATE INDEX suppressions_email_idx ON suppressions (email_norm);The scope column holds global or a list or topic key such as topic:events. The expires_at column is for soft-bounce cool-downs. Leave it null for entries that never expire. The unique constraint makes inserts idempotent: the same bounce reported twice creates one row.
Insert with ON CONFLICT DO NOTHING:
INSERT INTO suppressions (email_norm, scope, reason, source)
VALUES (lower('[email protected]'), 'global', 'complaint', 'feedback_loop')
ON CONFLICT (email_norm, scope, reason) DO NOTHING;Writing to the list from every source
Entries arrive from several places, and each one must reach the same table.
- The unsubscribe endpoint and the one-click header handler.
- The preference centre, for scoped opt-outs.
- Bounce and complaint webhooks from your sending provider.
- Support tooling for manual requests.
Make each path call one function so the rules live in one place. The function also records a consent event, so the audit trail from the previous chapter stays complete.
def suppress(db, email: str, reason: str, source: str, scope: str = "global"):
"""Add a suppression entry. Safe to call repeatedly."""
email_norm = email.strip().lower()
db.execute(
"INSERT INTO suppressions (email_norm, scope, reason, source) "
"VALUES (%s, %s, %s, %s) "
"ON CONFLICT (email_norm, scope, reason) DO NOTHING",
(email_norm, scope, reason, source),
)
if reason == "unsubscribe":
db.execute(
"UPDATE subscribers SET status = 'unsubscribed' "
"WHERE lower(email) = %s",
(email_norm,),
)Checking before every send
The rule is simple: the check happens at the moment of sending, not when the campaign is built. A campaign may be prepared on Monday and sent on Thursday. An unsubscribe on Wednesday must still be honoured.
There are two places to apply the check, and you should use both.
- Audience query. When you select recipients, exclude suppressed addresses in the query. This keeps the batch small and the numbers honest.
- Per-message gate. Immediately before handing each message to the mail server, check again. This catches changes made while a long send was running.
The audience query uses NOT EXISTS, which handles null values and large tables better than NOT IN:
SELECT s.id, s.email
FROM subscribers s
WHERE s.status = 'confirmed'
AND NOT EXISTS (
SELECT 1
FROM suppressions x
WHERE x.email_norm = lower(s.email)
AND (x.scope = 'global' OR x.scope = 'topic:weekly_digest')
AND (x.expires_at IS NULL OR x.expires_at > now())
);The per-message gate is a small function that your sending code must call. Make it impossible to send without it by placing it inside the one function that talks to the mail provider.
def is_suppressed(db, email: str, scope: str) -> bool:
row = db.fetch_one(
"SELECT 1 FROM suppressions "
"WHERE email_norm = %s "
"AND (scope = 'global' OR scope = %s) "
"AND (expires_at IS NULL OR expires_at > now()) "
"LIMIT 1",
(email.strip().lower(), scope),
)
return row is not None
def send_marketing(db, mailer, email: str, scope: str, message):
if is_suppressed(db, email, scope):
return "skipped_suppressed"
mailer.send(email, message)
return "sent"Because send_marketing is the only path to the mailer, a new campaign type cannot forget the check.
Edge cases
Address variants. Gmail ignores dots and +tags in the local part, so [email protected] and [email protected] reach the same mailbox. Do not collapse these in general, because other providers treat them as different addresses. Suppress the exact address the person used. If you see people re-entering a suppressed address with a tag, handle that case in your policy rather than in code that guesses at provider rules.
Race conditions. A person may click unsubscribe while a batch is in flight. The per-message gate narrows this window but cannot close it, because messages already handed to the provider will still be delivered. State a processing time in your policy and keep it short. The CAN-SPAM Act allows ten business days, but a few minutes is a better target.
Re-subscription. If someone who unsubscribed signs up again, treat it as a new consent event. Remove the unsubscribe entry only after the new double opt-in confirmation completes, and record the removal in the audit trail. Never remove complaint or hard_bounce entries because of a sign-up form alone. A person who complained and now asks to return should be handled by a human decision.
Soft bounces. One temporary failure is not a reason to suppress. Count consecutive failures, and add a soft_bounce_limit entry with an expires_at after a threshold such as five failures across two weeks.
Backups and imports. Restoring an old database backup can delete recent suppressions. Keep suppression data in a store that you restore separately, or replay recent events after a restore. Run import jobs through is_suppressed before they create subscribers.
Hashed entries. If you must keep a suppression after erasure, store a salted hash of the normalised address in a separate column or table. Compare by hashing the address at check time. Keep the salt secret and document why you keep the record.
Common mistakes
- Storing suppression only as a subscriber
status, which an import can overwrite. - Checking case-sensitively, so
[email protected]slips past an entry for[email protected]. - Using
NOT INwith a subquery that can return nulls, which returns no rows or the wrong rows. - Applying a topic-scoped opt-out as a global one, which removes people from mail they still want.
- Deleting suppression rows when cleaning "inactive" data.
- Ignoring complaint feedback, which keeps mailing people who have reported you as spam.
Testing the behaviour
Write tests that prove the guarantees, not just the happy path.
- Suppress an address, then run the audience query. It must not appear.
- Suppress an address after the audience is built, then call
send_marketing. It must returnskipped_suppressedand the mailer must not be called. - Call
suppresstwice with the same arguments. The table must hold one row. - Add a topic-scoped entry. A send for another topic must still go out.
- Add an entry with a past
expires_at. The address must be mailable again.
Exercise
A campaign is built on Monday for 50,000 recipients and sent in batches over Thursday. A subscriber unsubscribes on Wednesday evening. Where must the suppression check run so this person is not mailed, and why is checking only at build time not enough?
Show answer
The check must run at send time, in the audience selection for each batch and again in the per-message gate just before the mail provider is called. Checking only on Monday builds a recipient list that does not know about Wednesday's unsubscribe, so the person would still be mailed.
Exercise
A user unsubscribes from the "events" topic only. You store this as a suppression entry. What value should scope have, and why should you not use global?
Show answer
Use a scoped value such as topic:events. A global entry would block every message, including topics the person still wants, such as the weekly digest. That removes a willing subscriber and defeats the purpose of the preference centre.