Sub topic 8
Writing the sunset policy
This chapter assumes you already know why inactive addresses hurt sender reputation, how to define an engaged subscriber, and how to choose an inactivity window. It also assumes you can read basic SQL and Python. Here you combine those decisions into one written policy that a teammate can apply without asking you what you meant.
What a sunset policy is
A sunset policy is a written rule set that says when a subscriber stops receiving your mail, what you try first, and what you record. Without a written policy, each cleanup becomes a one-off judgment call. One person suppresses everyone with no opens in 90 days. Another person leaves the list alone for two years. Neither choice can be defended or measured later.
A good policy has seven parts:
- Scope: which lists and which kinds of mail the policy covers.
- Engagement definition: which events count as proof that a person is still reading.
- Inactivity window: how long without engagement makes a subscriber a candidate.
- Re-engagement step: what you send before you act, and how long people have to respond.
- Suppression action: what happens to subscribers who do not respond.
- Exceptions: who the policy skips, and why.
- Records and review: what you log, and when you revisit the numbers.
The next sections go through each part and show how to write it down so the rules can be tested.
Scope
State which mail the policy governs. Most policies apply to marketing and newsletter mail. They usually do not apply to transactional mail such as receipts, password resets, and shipping notices, because the recipient requested that mail by taking an action. Chapter 9 of this tutorial covers exceptions in detail, so here you only need to name the boundary.
Also state which lists the policy covers. If you run a weekly newsletter and a monthly product digest, you may need a different window for each. A subscriber can be inactive on one list and active on another. Decide whether the policy works per list or per address, and write that down. Per address is simpler and protects reputation better, because mailbox providers judge the sending domain and IP, not the list. Per list is more generous to low-frequency lists.
Engagement definition
Your policy must name the events that count. The spine for this tutorial recommends clicks and purchases, not opens, because privacy features such as Apple Mail Privacy Protection preload images and inflate open counts. A policy that counts opens will keep many dead addresses alive.
Write the definition as an explicit list. For example:
- Counts as engagement: a click on a tracked link, a purchase, a reply to a message, a preference-center visit, a login to your product.
- Does not count: an open, an email delivery, a bounce that was later retried.
Be careful with clicks. Some security scanners click every link in a message before the recipient sees it. If you see subscribers with a click on every message within a second of delivery, treat those clicks as suspect and exclude them. State the rule you use, such as ignoring clicks that happen within a few seconds of delivery, so the policy is reproducible.
Inactivity window
The window is the number of days without engagement after which a subscriber becomes a candidate. The right number depends on your cadence. A daily sender may use 60 or 90 days. A monthly sender needs much longer, because 90 days is only three messages.
A practical rule is to require that the subscriber received enough messages to have had a fair chance to engage. Many senders use a floor of about six to ten sends, as well as a number of days. The example in this chapter uses 180 days, which suits a weekly or twice-weekly sender.
Write the window as a number in the policy, and write the reasoning beside it. If someone later changes the cadence from weekly to daily, the reasoning tells them the number needs review.
Re-engagement step and grace period
Before suppression, the policy should require one attempt to win the subscriber back. State the following:
- The message or short series that is sent, and when.
- The success criterion. A click or a purchase counts, and an open does not.
- The grace period, which is the time the subscriber has to respond before suppression.
A 30-day grace period is a common choice. It is long enough for someone on vacation to return and short enough that the list does not sit in limbo.
The policy should also say what happens during the grace period. Do subscribers keep receiving regular mail? Most senders pause regular campaigns to these people so the only message they receive is the re-engagement message. If you keep sending, you gain nothing in reputation, because you are still mailing the unengaged group.
Turning the policy into stages
Each subscriber is in exactly one stage at any time. The stages form a small state machine, which is useful because you can test it.
The Python function below implements the stage decision. It takes the dates the policy cares about and returns a stage name.
from datetime import datetime, timedelta
def sunset_stage(
subscribed_at: datetime,
last_engaged_at: datetime | None,
reengagement_sent_at: datetime | None,
now: datetime,
window_days: int = 180,
grace_days: int = 30,
) -> str:
reference = last_engaged_at or subscribed_at
if now - reference < timedelta(days=window_days):
return "active"
if reengagement_sent_at is None:
return "send_reengagement"
if now - reengagement_sent_at < timedelta(days=grace_days):
return "waiting"
return "suppress"Three details in this function are worth noticing.
First, last_engaged_at or subscribed_at handles subscribers who never engaged. The clock for them starts at signup, so a person who joined 200 days ago and never clicked is a candidate, but a person who joined 20 days ago is not.
Second, the function does not check whether engagement happened after the re-engagement message. Suppose a subscriber clicks during the grace period. Then last_engaged_at moves forward and the first check returns "active", so the click rescues them. This works only if your pipeline updates last_engaged_at before it runs the stage decision.
Third, a subscriber who was rescued once and then goes inactive again still has an old reengagement_sent_at. The function would suppress that person immediately, with no new re-engagement message. A real implementation should clear reengagement_sent_at when the subscriber engages, or store it per cycle. Put this rule in the policy: each inactivity cycle gets its own re-engagement attempt.
Finding candidates with SQL
The policy needs a query that produces the candidate list. This PostgreSQL query lists subscribed addresses that joined more than 180 days ago and have no click or purchase in the last 180 days.
SELECT s.id,
s.email,
MAX(e.occurred_at) AS last_engaged_at
FROM subscribers s
LEFT JOIN engagement_events e
ON e.subscriber_id = s.id
AND e.event_type IN ('click', 'purchase')
WHERE s.status = 'subscribed'
AND s.subscribed_at < now() - interval '180 days'
GROUP BY s.id, s.email
HAVING MAX(e.occurred_at) IS NULL
OR MAX(e.occurred_at) < now() - interval '180 days';The LEFT JOIN keeps subscribers who have no matching events, and that is what lets the HAVING MAX(e.occurred_at) IS NULL branch find people who never engaged. The event filter sits in the ON clause, not in WHERE. If you moved e.event_type IN (...) into WHERE, the left join would behave like an inner join and you would lose the never-engaged group, which is often the largest one.
The query uses s.subscribed_at < now() - interval '180 days' to leave out new subscribers. It does not yet skip people who are in a grace period or on an exception list. Add those filters from your own tables before you act on the result.
Suppression action
State what happens at the end of the grace period. The usual answer is suppression, which means the address stays in your database but is blocked from receiving marketing mail. Suppressing is better than deleting because it lets you honor the decision later, prevents the address from being re-imported by accident, and keeps a record. The next-but-one chapter covers this in detail. In the policy, write one sentence, for example: "Subscribers who do not click or purchase within 30 days of the re-engagement message are moved to suppressed status and receive no marketing mail."
Exceptions
List who the policy skips. Common entries are subscribers who joined recently, people with an open support case, customers with an active paid plan, and seasonal buyers whose purchase cycle is longer than your window. For each exception, record the reason and the person who approves it. An exception list with no owner grows until the policy stops doing anything.
Records and review
The policy should say what you log for each decision: the subscriber ID, the stage, the date, the window and grace values in force, and the reason. This log lets you answer a complaint, reverse a mistake, and measure results later. Also set a review date, usually once or twice a year, when you compare the window against deliverability and revenue results.
Common mistakes
| Mistake | Effect | Fix |
|---|---|---|
| Counting opens as engagement | Privacy-inflated opens keep dead addresses active | Use clicks and purchases |
| Filtering events in `WHERE` after a left join | Never-engaged subscribers vanish from the result | Put the event filter in the `ON` clause |
| Reusing an old `reengagement_sent_at` | A returning subscriber is suppressed with no new attempt | Clear it on engagement, or store it per cycle |
| One window for every cadence | Monthly readers are suppressed too early | Set the window per list, with a send-count floor |
| No named owner for exceptions | The exception list grows without limit | Record a reason and an approver for each entry |
A sample policy
Here is a short example you can adapt. It fits a weekly newsletter.
- Scope: marketing and newsletter mail to all lists. Transactional mail is excluded.
- Engagement: a tracked click, a purchase, a reply, or a product login. Opens do not count. Clicks within five seconds of delivery are ignored.
- Window: 180 days without engagement, measured from the last engagement or from signup if there is none.
- Re-engagement: one message with a single clear link, sent once per inactivity cycle. Regular campaigns are paused for that subscriber.
- Grace period: 30 days. A click or purchase returns the subscriber to active.
- Action: suppress after the grace period with no engagement.
- Exceptions: subscribers who joined in the last 180 days, customers with an active plan, and anyone on the approved exception list.
- Records: log each stage change with the date, the parameters, and the reason.
- Review: every six months.
Exercise
A subscriber joined 240 days ago, never clicked, and received a re-engagement message 12 days ago. Using the default values of sunset_stage (window 180 days, grace 30 days), what stage does the function return, and why?
Show answer
It returns "waiting". The reference date is the signup date, 240 days ago, which is beyond the 180-day window, so the subscriber is not active. A re-engagement message has been sent, and 12 days is less than the 30-day grace period, so the subscriber is in the waiting stage.
Exercise
A colleague changes the SQL query so that e.event_type IN ('click', 'purchase') is in the WHERE clause instead of the ON clause. What happens to subscribers who never engaged, and why?
Show answer
They disappear from the results. A WHERE condition on the joined table rejects rows where e.event_type is NULL, which is the case for subscribers with no events. That turns the LEFT JOIN into an inner join, so the HAVING MAX(e.occurred_at) IS NULL branch can never match.