Skip to content
Tutorials Center
My learning

Topics

Lesson 27 of 40 ยท Growth, SEO and Analytics

Transactional Email and Customer Lifecycle

How shops use email: order confirmations, shipping and receipts, deliverability with SPF, DKIM and DMARC, abandoned cart flows and subscription billing, with a live template demo.

After a shopper pays, email is the main way your shop talks to them. The confirmation proves the order was received, the shipping email says when to expect it, and a receipt is often needed for accounting or returns. These are transactional messages: they are triggered by something the customer did and they carry information the customer needs. They are different from marketing messages such as newsletters, which promote products and need separate permission in many countries.

This lesson covers what to send, how to make sure it arrives, how to build templates safely, and how recurring flows (abandoned carts and subscriptions) fit around the order. Sending services differ, so the focus is on the rules every service shares.

The messages an order needs

A normal order produces a small, predictable set of emails, each tied to a state change in The Order Lifecycle and State Machines:

Trigger Message Must contain
Order placed and paid Order confirmation Order number, items, prices, tax, shipping address, payment method (last digits only), support contact
Shipment created Shipping notice Carrier, tracking link, items in this parcel (see split shipments)
Delivered Delivery notice (optional) Delivery date, return instructions
Refund issued Refund notice Amount, method, when the money appears
Account created or password reset Account email A single-use link with a short expiry
Return approved Return label Label, deadline, instructions

Send these from your system when the event happens, not from a person's mailbox. Build the email from a snapshot of the order (prices, addresses and names as they were at purchase time), not from the live catalog, otherwise a later price change rewrites history in the template. Include enough for the shopper to act without logging in, but never a full card number, a password or a plain-text secret.

Because a payment webhook may arrive twice, protect against double sends in the same way you protect payments: store a record such as "order 1042 confirmation sent" and check it before sending, or use a unique key per message. Sending two confirmations looks careless; sending none creates support tickets.

Do the sending in a background job. An SMTP provider can be slow or down, and the shopper should not wait on it during checkout. Retry with backoff, and log the provider's message id so support can answer "did you send it?".

Deliverability: SPF, DKIM and DMARC

An email that lands in spam is the same as one never sent. Mailbox providers decide on reputation and on proof that you are allowed to send for your domain. Three DNS-based standards give that proof:

  • SPF lists which servers may send mail for your domain.
  • DKIM signs each message with a private key; receivers check the signature against a public key in your DNS.
  • DMARC tells receivers what to do when SPF and DKIM do not line up with the visible From domain (none, quarantine or reject) and where to send reports.
flowchart LR
    S["Your shop<br/>or email service"] -->|"message + DKIM signature"| R["Receiving mail server"]
    R -->|"SPF: is this IP allowed?"| D["Your DNS"]
    R -->|"DKIM: fetch public key"| D
    R -->|"DMARC: policy?"| D
    R --> I["Inbox, spam or rejected"]

The receiver asks your DNS three questions before deciding where the message goes.

The records look like this (read-only examples; your provider gives the exact values):

TEXT
shop.example.            TXT  "v=spf1 include:mail.provider.example -all"
sel1._domainkey.shop.example.  TXT  "v=DKIM1; k=rsa; p=MIIB...public-key..."
_dmarc.shop.example.     TXT  "v=DMARC1; p=quarantine; rua=mailto:[email protected]"

Practical advice:

  • Send transactional mail from a subdomain such as orders.shop.example, separate from marketing, so a spam complaint on a newsletter does not damage order emails.
  • Start DMARC with p=none and read the reports. Move to quarantine and then reject once every legitimate sender passes.
  • Use only one SPF record per domain; a second record breaks both. SPF also has a limit of ten DNS lookups.
  • Keep bounce and complaint rates low. Remove addresses that hard-bounce; never keep mailing them.
  • Use a real reply-to address, plain text alongside HTML, and avoid image-only emails.

Building templates safely

Email HTML is old-fashioned: tables, inline styles, no modern CSS you can rely on, and clients that differ widely. Keep templates simple and test them in a few clients.

The bigger risk is data. Customer names, addresses and product names are user-controlled text. If you paste them into HTML without escaping, a customer who enters <b> or <a href=...> in their name can alter the email. Escape every value for the context where it goes: HTML text, an attribute, or a URL. Format money from minor units at the edge (Representing Money Correctly), using the order's currency and the customer's locale (Currencies and Localization).

JS Render an order confirmation safely

Press Run (or Ctrl + Enter) to see the console output here.

No output.

The HTML part shows the hostile name as harmless text, while the plain-text part needs no escaping because it is not HTML. Sending both parts improves deliverability and helps readers that block HTML.

Abandoned cart emails

A shopper who added items and left is often a few hours from buying. A short abandoned-cart flow can recover a real share of those orders. A common structure:

  1. About one hour after leaving: a reminder with the cart contents and a link back. No discount.
  2. About a day later: reassurance (returns, delivery times, reviews), or a low-stock note if it is true.
  3. A few days later, optionally: a last reminder, possibly with a small incentive.

Rules that keep it honest and legal:

  • You need an email address. It is usually collected in the first checkout step, so a guest who typed it and left is reachable, but consent rules vary by country. In many places a reminder about a basket they started falls under legitimate interest, while a marketing discount needs opt-in. Check the rules for your markets (GDPR, Consumer Law and Accessibility).
  • Stop the flow the moment an order is placed, and re-check stock and price before every send. Showing a sold-out item in a "come back" email is worse than saying nothing.
  • Make the link restore the cart (Designing the Cart) with a signed, expiring token instead of a guessable cart id.
  • Always include an unsubscribe route for the marketing-style steps.
  • Do not fake urgency such as invented countdowns. It harms trust and is illegal in some places.

Subscriptions and recurring billing

A subscription turns one order into a repeating one. The shop stores a payment method (as a token, never raw card data, see PCI DSS Scope and 3-D Secure), a plan and a billing schedule, and then creates a new order and charge at each renewal. Things to design on purpose:

  • Billing cycles and anchor dates. A monthly subscription started on the 31st needs a rule for shorter months (usually the last day of the month).
  • Price changes. Decide whether existing subscribers keep their old price, and give notice before a change.
  • Failed payments. Cards expire and banks decline. Instead of canceling at once, run dunning: retry on a schedule, email the customer to update the card, and only then pause or cancel.
  • Proration. When a customer upgrades mid-cycle, charge or credit only the part of the period that changed.
  • Pause, skip and cancel. Make them easy. Cancellation that is hard to find leads to chargebacks and legal problems.
  • Strong authentication. Renewals happen without the customer present, so the first payment must set up the permission correctly for off-session charges.
JS Renewal dates and a dunning schedule

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Notice how February clamps to the 28th and March snaps back to the 31st: the anchor day is remembered, not recomputed from the previous renewal.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Why should order emails be built from a snapshot of the order instead of the live catalog?

    The order records what was agreed at purchase time. Reading the live catalog would show today's data, which may differ.
  2. 2. What does DKIM do?

    DKIM adds a cryptographic signature checked against a public key in your DNS. SPF lists allowed senders, and DMARC sets the policy.
  3. 3. A customer enters a name containing HTML tags. What must the email template do?

    Customer text is untrusted. Escaping stops it from changing the structure of the message, and it applies to every field you insert.
  4. 4. A monthly subscription started on January 31. What is the usual renewal date in February?

    Clamp to the last valid day of the month, then return to the anchor day when the month is long enough.
  5. 5. When should an abandoned cart flow stop?

    Reminding someone about a purchase they already made is confusing. Check for an order before every send.

Summary

  • Transactional emails are triggered by order events and carry information the customer needs; build them from the order snapshot and send them from background jobs once.
  • SPF, DKIM and DMARC prove you may send for your domain; use a separate subdomain for transactional mail.
  • Escape all customer-provided text, format money from minor units, and send both HTML and plain text.
  • Abandoned cart flows need consent awareness, a stop when the order is placed, fresh stock and price checks, and honest wording.
  • Subscriptions need anchor-date rules, proration, a dunning schedule for failed payments, and easy cancellation.

Next, the other side of trust: Fraud and Risk Management.