Sub topic 10
Keeping transactional and marketing traffic apart
This chapter assumes you know how SMTP delivery works and what an email service provider (ESP) does. It also assumes you can read a DNS TXT or CNAME record, and that you have seen SPF, DKIM, and DMARC introduced in the previous chapter. Here you will learn how to split your sending into separate streams, what to split, and what can still go wrong.
Why separation matters
Mailbox providers such as Gmail, Outlook, and Yahoo judge mail by the identity that sent it. That identity is the domain in the DKIM signature, the domain in the From header, the bounce (Return-Path) domain, and the IP address. Each of these builds a reputation from recipient behavior: opens, deletions without reading, spam complaints, and bounces.
Transactional and marketing mail produce very different behavior:
- Transactional messages such as password resets and receipts are expected, get opened quickly, and almost never draw complaints.
- Marketing mail is optional. Even a well-run newsletter gets some complaints and a lot of ignored messages. A promotion to an older list can draw many more.
If both share one identity, marketing's weaker numbers pull down the reputation of the messages users are waiting for. A user who clicks "Reset password" and waits for a message that lands in spam or arrives 20 minutes late will contact support or leave. Separation limits the damage: a bad campaign hurts the marketing stream, and the transactional stream keeps its own reputation.
Separation also helps with operations and compliance. You can set different retry rules, retention periods, and unsubscribe behavior for each stream, and you can read each stream's metrics without mixing them.
What a stream is
A stream is a set of sending settings used for one category of mail. The layers you can separate are:
| Layer | Transactional example | Marketing example | Why it matters |
|---|---|---|---|
| Sending domain | `tx.example.com` | `mail.example.com` | Domain reputation is the strongest signal at most large providers |
| Authentication keys | DKIM selector under `tx.` | DKIM selector under `mail.` | Each stream signs with its own key, so you can rotate or revoke one without touching the other |
| Return-Path domain | `bounce.tx.example.com` | `bounce.mail.example.com` | Keeps SPF alignment and bounce handling per stream |
| IP address or pool | Pool A | Pool B | Protects against IP-level reputation damage |
| ESP credentials | API key or message stream 1 | API key or message stream 2 | Lets you limit access and keep settings, webhooks, and logs apart |
| Suppression lists | Hard bounces and complaints | Unsubscribes, bounces, complaints | Prevents a marketing opt-out from blocking a password reset |
| Monitoring | Delivery latency, bounce rate | Complaint rate, engagement | Different thresholds apply to each |
You do not have to separate all layers on day one. The domain and credentials layers are cheap and give the most benefit. Dedicated IPs add cost and upkeep.
Separating by subdomain
The standard approach is one subdomain per stream, both under your organizational domain. The root domain (example.com) is then kept for people: employees' day-to-day mail, which also needs its own authentication.
; Transactional stream
tx.example.com. TXT "v=spf1 include:_spf.tx-provider.example.net -all"
s1._domainkey.tx.example.com. CNAME s1.domainkey.tx-provider.example.net.
bounce.tx.example.com. TXT "v=spf1 include:_spf.tx-provider.example.net -all"
; Marketing stream
mail.example.com. TXT "v=spf1 include:_spf.esp.example.net -all"
m1._domainkey.mail.example.com. CNAME m1.domainkey.esp.example.net.
bounce.mail.example.com. TXT "v=spf1 include:_spf.esp.example.net -all"
; Policy for the organizational domain and, by inheritance, both subdomains
_dmarc.example.com. TXT "v=DMARC1; p=none; sp=none; rua=mailto:[email protected]"Points to check in this layout:
- SPF is evaluated per domain, so each subdomain needs its own record. An SPF record on
example.comdoes not covertx.example.com. - Many ESPs publish a bounce domain through a CNAME instead of a TXT record. Follow your provider's instructions for the exact record type.
- DMARC looks for a record at
_dmarc.<from-domain>first, then falls back to the organizational domain. Thesp=tag sets the policy for subdomains. Without it, subdomains inheritp=. - You can also publish
_dmarc.tx.example.comand_dmarc.mail.example.comrecords. Separate records let you move one stream top=quarantineorp=rejectwhile the other is still in monitoring mode. - DMARC passes only if SPF or DKIM passes and the passing domain aligns with the From domain. Make sure your ESP signs with your subdomain, not its own shared domain.
How the pieces fit together
Routing in application code
The most important rule is that the application decides the stream from the message category, not from the caller's preference. The example below fails closed: an unknown category raises an error instead of falling back to a default stream, and marketing messages cannot be sent without an unsubscribe link.
import os
import smtplib
from dataclasses import dataclass
from email.message import EmailMessage
@dataclass(frozen=True)
class Stream:
name: str
host: str
port: int
user_env: str
password_env: str
from_address: str
STREAMS = {
"transactional": Stream(
name="transactional",
host="smtp.tx-provider.example.net",
port=587,
user_env="TX_SMTP_USER",
password_env="TX_SMTP_PASSWORD",
from_address="Example App <[email protected]>",
),
"marketing": Stream(
name="marketing",
host="smtp.esp.example.net",
port=587,
user_env="MK_SMTP_USER",
password_env="MK_SMTP_PASSWORD",
from_address="Example Weekly <[email protected]>",
),
}
CATEGORY_TO_STREAM = {
"password_reset": "transactional",
"order_receipt": "transactional",
"security_alert": "transactional",
"newsletter": "marketing",
"promotion": "marketing",
}
def send(category, to, subject, body, unsubscribe_url=None):
try:
stream = STREAMS[CATEGORY_TO_STREAM[category]]
except KeyError:
raise ValueError(f"Unknown message category: {category!r}")
msg = EmailMessage()
msg["From"] = stream.from_address
msg["To"] = to
msg["Subject"] = subject
msg.set_content(body)
if stream.name == "marketing":
if not unsubscribe_url:
raise ValueError("Marketing messages need an unsubscribe URL")
msg["List-Unsubscribe"] = f"<{unsubscribe_url}>"
msg["List-Unsubscribe-Post"] = "List-Unsubscribe=One-Click"
with smtplib.SMTP(stream.host, stream.port) as server:
server.starttls()
server.login(os.environ[stream.user_env], os.environ[stream.password_env])
server.send_message(msg)Each stream reads its own credentials from the environment. A leaked marketing key then cannot send as the transactional domain, and revoking one does not interrupt the other.
Suppression: what to share and what to split
Suppression lists are where separation is most often done wrongly. Treat the three suppression reasons differently:
- Unsubscribes belong to the marketing stream only. A person who leaves your newsletter still needs password resets and receipts. Do not suppress their address in the transactional stream because of a marketing opt-out.
- Hard bounces (the address does not exist) should be shared across streams. Mailing a dead address from either stream hurts reputation.
- Spam complaints are a judgment call. A complaint on a newsletter means the person does not want that newsletter. It does not always mean they want no account mail. However, a complaint on a transactional message is a serious signal and the address should be reviewed.
Document the rule you pick and apply it in code, not by hand.
IP addresses: shared or dedicated
Separate streams on a shared IP pool is a reasonable starting point for small senders, because the ESP manages the pool's reputation. A dedicated IP gives you control, but you carry the responsibility:
- A new dedicated IP has no history and must be warmed up by increasing volume gradually.
- Low-volume senders do not generate enough signal for providers to build a stable reputation, so a dedicated IP can perform worse than a well-managed shared pool.
- Transactional traffic is often steady and low-volume, so it is a weaker fit for its own IP than a large, regular marketing send.
Consider a dedicated IP when your volume is high and regular, or when your ESP's shared pool has shown problems you cannot control. Subdomain separation needs no such threshold and should come first.
Failure modes and gotchas
- Promotional content in the transactional stream. Adding a "20% off your next order" banner to a receipt may turn the message into a promotional one, in law and in how providers treat it. The earlier chapter on mixed-content messages covers the classification. In the stream model, such a message belongs in the marketing stream unless it passes your classification rules.
- Shared reply-to, shared From name, or look-alike domains. If transactional mail comes from
[email protected]and marketing comes from[email protected], you have separated nothing at the domain level. - Unrelated domains. Using a completely different domain for marketing (
example-news.com) separates reputation, but it costs brand recognition and can look like phishing. Subdomains of one organizational domain are usually the better trade. - Reputation is not perfectly isolated. Some mailbox providers factor in the parent domain, so a severely damaged marketing subdomain can still cast a shadow on the rest. Isolation reduces the risk but does not remove it.
- Late-moving DMARC. Keep
p=nonewhile you read reports and confirm every legitimate source is aligned. Only then move one stream at a time to a stricter policy. - Warm-up of the new subdomain. Moving an existing marketing list onto a new subdomain means starting a new reputation. Ramp volume up over days or weeks, beginning with your most engaged recipients.
- Monitoring one number for both. A blended bounce rate of 2% can hide a healthy transactional stream and a struggling marketing stream. Always report per stream.
Summary checklist
- Give each stream its own subdomain, DKIM key, and bounce domain.
- Publish SPF per subdomain and confirm DKIM and SPF align with the From domain.
- Use separate ESP credentials, and keep them in environment variables or a secrets manager.
- Route by message category, and fail closed on unknown categories.
- Scope unsubscribes to marketing and share hard bounces across streams.
- Start on shared IPs and move to dedicated ones only when volume justifies it.
- Monitor each stream with its own thresholds.
Exercise
Your marketing team wants to send a one-off "we have updated our terms of service" notice and add a promotional banner. Which stream should send it, and why?
Show answer
Send it through the marketing stream if it carries the promotional banner. A message with promotional content is treated as promotional, so sending it from the transactional stream would put that stream's reputation at risk. If the notice has no promotion and is required for the account relationship, the transactional stream is appropriate. The deciding factor is the content, not how important the sender considers the message.
Exercise
A user clicks the unsubscribe link in your newsletter. Two days later they request a password reset. Should the reset email be suppressed? Which suppression list holds the address?
Show answer
No. The unsubscribe applies only to the marketing stream and is stored in the marketing suppression list. The transactional stream does not read that list, so the reset email is sent. Suppressing it would break a function the user asked for.
Exercise
Your DMARC record at _dmarc.example.com is "v=DMARC1; p=none; rua=mailto:[email protected]". You want to enforce p=reject for tx.example.com only, while mail.example.com stays in monitoring mode. What do you change?
Show answer
Publish a separate record at _dmarc.tx.example.com with "v=DMARC1; p=reject; rua=mailto:[email protected]". Without this record, tx.example.com inherits the organizational policy, and mail.example.com keeps inheriting p=none. Before switching, check the aggregate reports to confirm that all legitimate sources for tx.example.com pass SPF or DKIM with alignment.