Sub topic 1
What Consent Means for an Email List
Prerequisites
Assume you understand basic email sending, HTML forms, HTTP GET and POST requests, SQL, and one general-purpose programming language. This chapter focuses on the design choices behind a consent-aware subscription flow.
What Consent Means for an Email List
Consent is a clear, informed, and voluntary agreement to receive specific messages. A prechecked box, unclear wording, or bundled agreement does not provide strong evidence of consent.
State what the subscriber will receive, how often, and who will send it. Store the wording shown at signup, the time, the source page, and relevant request data. Consent for product updates does not automatically cover unrelated promotions.
Legal and Mailbox-Provider Expectations
Privacy and email laws differ by location. GDPR and ePrivacy rules often require prior, demonstrable permission. CAN-SPAM focuses on identification and straightforward opt-out. CASL generally requires consent and evidence. Mailbox providers also judge complaint rates, engagement, authentication, and unsubscribe behavior.
Treat these as engineering requirements:
- Obtain permission before marketing mail.
- Identify the sender accurately.
- Provide a working unsubscribe path in every message.
- Apply unsubscribes before every send.
- Keep evidence without retaining unnecessary personal data.
Single Opt-In Versus Double Opt-In
Single opt-in adds the address immediately after form submission. It has less friction but can admit typos, bots, and addresses submitted by someone else.
Double opt-in, also called confirmed opt-in, sends a confirmation message first. The address becomes active only after the recipient confirms. It reduces false subscriptions and produces stronger evidence, but some legitimate subscribers will not complete the extra step.
| Model | Main benefit | Main cost |
|---|---|---|
| Single opt-in | More immediate list growth | Weaker address ownership evidence |
| Double opt-in | Cleaner list and clearer consent proof | Lower completion rate |
Modelling the Subscriber Lifecycle
Use explicit states rather than inferring status from whether an email exists:
pending records an unfinished signup. confirmed permits marketing sends. unsubscribed must remain suppressed even if an old confirmation link is used.
Building Signed, Expiring Confirmation Tokens
A confirmation token should contain its purpose, address, and expiry. Sign the payload with HMAC-SHA256. Verify the signature before parsing trusted values, compare signatures in constant time, reject expired tokens, and never reuse a confirmation token for another action.
import base64, hashlib, hmac, json, os, time
SECRET = os.environ.get("TOKEN_SECRET", "development-only-secret").encode()
def issue(email, ttl=172800):
payload = json.dumps(["confirm", email, int(time.time()) + ttl],
separators=(",", ":")).encode()
sig = hmac.new(SECRET, payload, hashlib.sha256).digest()
enc = lambda b: base64.urlsafe_b64encode(b).rstrip(b"=").decode()
return enc(payload) + "." + enc(sig)
def verify(token):
try:
p, s = token.split(".")
dec = lambda x: base64.urlsafe_b64decode(x + "=" * (-len(x) % 4))
payload, sig = dec(p), dec(s)
expected = hmac.new(SECRET, payload, hashlib.sha256).digest()
if not hmac.compare_digest(sig, expected):
return None
purpose, email, expiry = json.loads(payload)
return email if purpose == "confirm" and expiry >= time.time() else None
except (ValueError, TypeError, json.JSONDecodeError):
return NoneExercise
Which state should a new email enter before the subscriber confirms?
Show answer
pending; it should not receive marketing mail until confirmation succeeds.