Transactional e-mail templates with variables: write once, fill in each customer's details

E-mail·· 53 views· 3 min read

The short answer: a template stores the subject and the body (HTML, text or both) with variables such as {{name}}. When sending, your system only gives the template_id and the values in variables. You change the wording in the template and the code stays the same.

Creating a template

1 On the Transactional e-mail page in My MozOut, open Templates and create one, or use POST /v1/email/templates.
2 Give it a name of up to 100 characters, unique in the account, such as "Invoice ready".
3 Write the subject and the body, with variables in double curly braces: Invoice {{number}} is ready.
4 Save. The page shows the template number in the API: that is the template_id. The API answer also lists the variables it found.

Sending with the template

curl https://api.mozout.com/v1/email/messages \
-H "Authorization: Bearer sandbox_..." \
-H "Content-Type: application/json" \
-H "Idempotency-Key: fatura-2026-214" \
-d '{"from": "Your Company <invoices@yourcompany.com>",
"to": ["ana@example.com"],
"template_id": 12,
"variables": {"name": "Ana", "number": "FT 2026/214",
"amount": "1,250.00", "date": "30/11/2026"}}'

Any subject, html or text you leave out comes from the template. If you send one of them, what you sent wins for that e-mail.

Taking care with variables

Rule Why
In HTML, values are escaped A name with < or & shows as text, so it neither breaks the e-mail nor lets odd code in.
variables is an object of names and values A list or a loose string gives a validation error.
Use the same names in the template and the send A variable with no value stays unfilled. Check with a Sandbox send.
Keep sensitive data out of the template text A password or a full card number never goes by e-mail.

Changing or deleting

With PATCH /v1/email/templates/{id} only the fields you send change, for example just the subject. DELETE /v1/email/templates/{id} removes it. If the account already has the maximum number of templates, delete one you do not use before creating another.

One template per situation, not one for everything: "Invoice ready", "Reset your password", "Order shipped". Wording ideas for each are in what a good transactional message says.

Want to automate your invoices and confirmations with templates? See the API page.

See the API page

SEE ALSO

Sending a transactional e-mail through the API: the fields of POST /v1/email/messages

Password reset, order and invoice e-mails: what a good transactional message says, with examples

Attaching invoices and tickets to a transactional e-mail: base64, size limit and refused files

Testing transactional e-mail without sending: Sandbox keys, test mode and simulated bounces

Building an HTML e-mail that displays everywhere: width, images and dark mode

Sending transactional e-mails in a batch: one request, many messages and the result of each

RECOMMENDED PRODUCT

Professional e-mail on your domain

Mailboxes in your company name, no adverts, with spam filtering. from R118.80/mo (3-year plan, with coupon)

See plans
Was this answer helpful? Your answer helps us improve this article.