Sub topic 5
Transactional email: messages triggered by user actions
This chapter assumes you know how email is sent and received, what an email service provider (ESP) does, and what a DNS record is. It covers the working model of transactional email and the errors teams make most often.
What makes an email transactional
A transactional email is a message sent in response to one specific action by a user, or to an event on their account. The user expects it. They often need it to finish what they started.
Typical examples:
- Password reset links
- Order confirmations and receipts
- Shipping and delivery notices
- Sign-up verification and one-time codes
- Security alerts, such as a login from a new device
- Billing notices, such as a failed payment
Three properties define the category:
- One trigger. A single user action or account event causes the send.
- Only the needed information. The message contains what the recipient needs for that action and little else.
- No promotional content. Offers, upsells, and campaign banners do not belong here.
If a message fails any of these, treat it as promotional until proven otherwise. The chapter on mixed-content messages covers the borderline cases.
A transactional message in code
The example below sends a password reset. It is sent because the user asked for it, it holds one link and one expiry time, and it has no marketing text.
import smtplib
from email.message import EmailMessage
msg = EmailMessage()
msg["From"] = "Example App <[email protected]>"
msg["To"] = "[email protected]"
msg["Subject"] = "Reset your password"
msg.set_content(
"You asked to reset your password.\n"
"Use this link within 30 minutes: https://example.com/reset?token=EXAMPLE\n"
"If you did not request this, you can ignore this message."
)
with smtplib.SMTP("smtp.example.com", 587) as server:
server.starttls()
server.login("smtp-user", "smtp-password")
server.send_message(msg)Note what the message does well:
- The subject says exactly what the email is.
- The link expires, which limits risk.
- The last line tells a recipient who did not ask what to do.
- The sender address and domain are the ones the application owns.
In production, keep the credentials out of the source code. Read them from environment variables or a secrets store.
The flow from action to inbox
Because the message is tied to a user action, speed matters. A reset link that arrives ten minutes late is a failed message, even if it is eventually delivered.
Consent and legal treatment
Transactional email does not need marketing consent. The recipient does not subscribe to it, and an unsubscribe link is usually not required. The legal reason is that the message relates to a transaction or relationship the user already has with you. Rules differ by region, so read the legal basics chapter before you rely on this.
That exemption covers only transactional content. Adding a promotion can pull the whole message into marketing rules.
Common errors
| Error | Why it hurts | Fix |
|---|---|---|
| Adding a sale banner to a receipt | The message may be treated as promotional, and the exemption can be lost | Keep receipts and notices free of offers |
| Sending from the same domain and IP as bulk campaigns | Complaints about marketing mail damage delivery of resets and codes | Use a separate sending stream |
| Slow sending queues | One-time codes expire before they arrive | Send transactional mail ahead of bulk mail |
| Vague subjects like "Update" | Users miss the message or mark it as spam | Name the action in the subject |
| Skipping authentication | Mailbox providers may reject or filter the message | Set up SPF, DKIM, and DMARC |
Practical guidance
- Send each message once per trigger, and make the send idempotent. A retry after a timeout should not email the user twice.
- Keep a plain-text part alongside any HTML part. Plain text renders everywhere.
- Log the provider's message ID so support can answer "did my email go out?"
- Monitor bounces. A hard bounce on a transactional address means the user cannot receive account-critical messages.
- Do not suppress transactional email because someone unsubscribed from marketing. Keep the two preferences separate.
Exercise
A shop sends an order confirmation that includes the order number, the delivery date, and a large banner offering 20% off the next purchase. Is this still a transactional email? What would you change?
Show answer
The banner adds promotional content, so the message is no longer purely transactional and may fall under marketing rules. Remove the banner so the confirmation holds only the order details, and send the offer as a separate promotional message to recipients who have consented to marketing.
Exercise
Why should a password reset email travel through a different sending stream from a weekly sale campaign?
Show answer
Bulk campaigns draw more spam complaints and unsubscribes, which lower the sender reputation of the shared domain or IP. If resets share that reputation, they are more likely to be delayed or filtered, and users cannot get into their accounts.