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. Earlier chapters introduced the three email types and consent. Here we look closely at the transactional type: what qualifies, how to build it well, and where it commonly goes wrong.
What makes an email transactional
A transactional email is sent in response to one specific action or event involving one recipient. The recipient asked for it, or needs it to complete or understand something they did. Common examples:
- Password reset links
- Email address verification and sign-up confirmation
- Order confirmations, receipts, and invoices
- Shipping and delivery notifications
- Security alerts, such as a login from a new device
- Account changes, such as a changed billing address
- Payment failures and subscription renewal notices
Three tests help you decide whether a message is transactional:
- Trigger. One action by the user, or one event on their account, causes the message. A calendar date or a marketing decision does not.
- Content. The message contains the information the recipient needs for that action and nothing more.
- Expectation. The recipient would be surprised or worried if the message did not arrive.
If a message fails any of these tests, treat it as promotional or as a newsletter. Later chapters cover mixed messages and the legal rules in detail. This chapter concentrates on the engineering and the content.
Why transactional email is treated differently
Transactional email differs from the other two types in several practical ways.
| Property | Transactional | Newsletter | Promotional |
|---|---|---|---|
| Trigger | One user action or account event | Schedule | Marketing decision |
| Audience | One recipient per event | A subscriber list | A segment or list |
| Consent basis | Relationship and the action itself | Subscription | Opt-in or other legal basis |
| Unsubscribe | Usually not offered for essential messages | Required | Required |
| Timing | Seconds | Planned | Planned |
| Typical open rate | Very high | Moderate | Lower |
Timing matters most. A password reset that arrives ten minutes late is a failed message, because the user has probably given up or tried again. Transactional email therefore needs a fast, reliable sending path, and that is the main reason it is usually kept separate from marketing traffic. The chapter on stream separation covers that design.
Consent also works differently. A person does not subscribe to receipts. The relationship and the action create the expectation. This is why essential transactional messages normally do not need an unsubscribe link. It is also why you must not abuse that exemption, as the section on content discipline explains.
Building a transactional message
Send from a dedicated address and subdomain
Use a sender address on a subdomain used only for transactional traffic, such as [email protected]. Many teams prefer an address that can receive replies, such as [email protected], because replies to receipts and account notices often contain real problems. If you use no-reply, give the recipient another way to reach you in the body of the message.
A minimal, correct example
The following Python script builds and sends a password reset message with the standard library. Replace the host, credentials, and addresses with your own values before running it. In production you would load the credentials from environment variables or a secrets store, never from source code.
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)Look at what the message does and does not contain:
- The subject states the purpose in plain words.
- The body explains why the user received it ("You asked to reset your password").
- It gives one action, one link, and an expiry time.
- It tells a recipient who did not make the request what to do.
- It has no banner, product recommendation, or discount.
Content discipline
The most common failure is adding marketing content to a transactional template. Teams do this because transactional messages have the highest open rates in the whole program, and a product manager wants to use that attention. The risks are real:
- Under US rules, a message with a commercial purpose alongside a transactional one can lose its transactional status, which brings the full set of commercial-email requirements. Under EU rules, adding promotion can remove the exemption from consent requirements. The legal chapter covers both.
- Mailbox providers measure how recipients react. If people stop opening receipts or mark them as spam because of promotional content, the damage to your sending reputation reaches the messages that really matter.
- A password reset buried in a promotion becomes harder to find and act on.
A practical rule: a transactional template may contain the information for its event, the sender's identity and contact details, and links needed to manage the account or order. Anything that tries to sell something does not belong in it.
Make the message robust to the reader's situation
Transactional messages are read in a hurry, often on a phone, and sometimes by someone anxious about a security event. Design for that:
- Put the key information in the subject and the first line: order number, amount, or the action required.
- Always include a plain-text part along with any HTML part. Many users and some security tools read plain text, and a missing text part is a common spam signal.
- Show the link as a visible, full URL in the plain-text part so it can be copied.
- Keep link domains consistent with your sending domain. Mismatched or shortened links in security messages look like phishing.
- State expiry times and what happens if the user ignores the message.
Reliability engineering for transactional sending
Because delivery speed and success matter so much, treat the sending path like any other critical dependency.
Use idempotency and deduplication
Retries are necessary, since networks fail. Retries without protection cause duplicates: two receipts, or two reset links where the first is invalidated by the second. Give every message a stable key built from the event, such as order-1042-confirmation, and refuse to send a second message for the same key. Many ESP APIs support an idempotency key. If yours does not, store sent keys in your own database before or when you hand the message to the ESP.
Send from a queue
Do not send email inside the web request that triggered it. A slow or failing ESP would then slow or break the user's checkout or sign-up. Instead, write the message to a queue or an outbox table and let a worker send it. The user's action succeeds immediately, and the worker retries on temporary failures.
Handle bounces and complaints
An ESP reports delivery results through events or webhooks. Handle at least these:
- Hard bounce. The address does not exist or permanently rejects mail. Stop sending to it and flag the account so the user can correct the address.
- Soft bounce. A temporary problem, such as a full mailbox. Retry with a limit.
- Spam complaint. The recipient marked the message as spam. For transactional mail this is a serious signal that the content or the trigger is wrong.
A password reset that hard bounces should show up in your application. Silent failure leaves a user locked out with no explanation.
Do not let tokens outlive their purpose
Links in transactional email often carry credentials. Make tokens random and single-use, give them a short expiry, and store only a hash of them on the server. Do not log full URLs that contain tokens. Some mail scanners follow links automatically, so a reset link that performs a destructive action on a plain GET request can be triggered without the user. Make the link open a page that asks the user to confirm.
Authentication and unsubscribe for transactional mail
Transactional mail needs the same sender authentication as all other mail. Publish SPF and DKIM for the sending domain, and a DMARC policy for the organizational domain. A reset email that lands in spam because DKIM is missing is a broken product feature. Later chapters cover the setup.
On unsubscribe, the rule of thumb is this. Messages that are strictly necessary to deliver a service the user requested, such as resets, receipts, and security alerts, do not carry an unsubscribe link. Optional account notifications, such as "someone commented on your post" or a weekly activity digest, sit in a gray area. They are triggered by the user's account, yet the user may not want all of them. Give these a notification preferences page and a link to it. That keeps them useful and reduces spam complaints.
Measuring transactional email
Open and click rates are less informative here than for marketing mail. A user who requests a reset needs to click, so a low click rate means the message failed. Better measures:
- Delivery time. Time from the triggering event to inbox placement, tracked at the median and at the 95th percentile.
- Delivery rate and bounce rate. Track hard bounces separately.
- Task completion. The share of reset emails followed by a successful password change, or of verification emails followed by a verified account.
- Complaint rate. Should stay very low.
Apple Mail Privacy Protection and similar features load images automatically, so opens are inflated and unreliable. Use completion of the task as your main signal.
Common errors
- Sending transactional mail from the same domain, IP address, and ESP stream as bulk marketing, so a bad campaign delays resets.
- Putting promotions in receipts and losing transactional status.
- Sending in the web request with no queue or retry.
- Reusing one
no-replyaddress and giving users no way to get help. - Sending HTML only.
- Using reset tokens that never expire or work more than once.
- Ignoring hard bounces so the same dead address keeps receiving mail.
- Treating every triggered message as exempt from unsubscribe, including optional notifications.
Exercises
Exercise
A shop sends an order confirmation containing the order number, items, total, and delivery address. The marketing team asks to add a "20% off your next order" banner below the total. Why is this a problem, and what is a safer approach?
Show answer
The banner adds a promotional purpose to a transactional message. The message may then be treated as commercial email, which brings consent and unsubscribe requirements, and recipients may react to it as marketing, which can raise complaints and hurt the reputation of the transactional stream. A safer approach is to keep the confirmation purely transactional and send the offer as a separate promotional message to recipients who have consented to marketing.
Exercise
Your checkout sends the receipt email inside the web request and retries three times on failure. Customers sometimes get two receipts, and checkout is slow when the ESP is slow. Describe two changes that fix both problems.
Show answer
First, move sending to a queue or outbox so a worker sends the message after checkout completes. This removes the ESP latency from the user's request and allows retries in the background. Second, use a stable idempotency key for each message, such as the order ID plus message type, and record it so a retry never produces a second send.
Exercise
A "weekly activity summary" is triggered by the user's account and sent every Monday. Is it strictly transactional? How should you handle opt-out?
Show answer
No. It is sent on a schedule, is not needed to complete any action, and the user may not want it. Treat it as an optional notification or a newsletter-type message, include a link to a notification preferences page or an unsubscribe link, and honor changes promptly.