Email Templates Transactional Email Email API Developer Guide

How to Build Reusable Email Templates with Variables

By Nimana · Last updated December 1, 2026 · 4 min read

Stop hand-writing every email. Learn how to build reusable templates with variables, test them, and manage changes safely, with examples you can copy.

Why This Matters

Many apps start by building each email as a string inside the code: a welcome message here, a receipt there, a password reset somewhere else. It works until you want to change a logo, fix a typo, or make ten emails look the same. Then you are editing HTML in a dozen places, and one of them is always missed.

A template solves this. You design the email once, mark the parts that change, and your app fills them in each time.

What a Template Is

A template is an email with blanks. The fixed parts, such as the layout, the colours, and the wording, live in the template. The changing parts, such as a customer's name or a reset link, are variables, placeholders that get replaced with real values when the email is sent.

A typical placeholder looks like this:

Hi {{ name }}, here is your link: {{ reset_url }}

When your app sends the email, it supplies name and reset_url, and each customer gets their own version.

Seven Tips for Good Templates

1. Start from a proven design

Do not begin with a blank page. Copy a ready-made transactional layout for the type of email you need, then adjust it to your brand.

2. Keep variables simple and well named

Use clear names such as first_name, order_number, and login_url. Avoid vague ones such as data1. Anyone who opens the template should understand it.

3. Personalise the subject line too

The subject is part of the template. A subject like "Your order #4821 is confirmed" is far clearer than "Order confirmation".

4. Plan for missing values

What should the email say if a name is missing? Decide in advance, and make sure your app always sends the values the template needs.

5. Keep one purpose per template

A password reset template should reset passwords, nothing more. Do not turn one template into a general-purpose email with many optional sections.

6. Design for phones and for plain text

Most people read email on their phones. Use a single column, big buttons, and short paragraphs. Also send a plain-text version for email clients that need one.

7. Test before you use it

Send the template to yourself with realistic values, including a very long name and a missing field. Check it in more than one email app.

Managing Changes Safely

Templates are shared by every email that uses them, so a mistake spreads quickly. A few habits help:

  • Test changes on a copy before you edit the live version.
  • Be careful with deletion. If your app still refers to a template that no longer exists, the sends will fail.
  • Keep a record of which template each part of your app uses.

Common Mistakes

  • Copying the same HTML into many places
  • Unclear variable names
  • No plan for missing data
  • Deleting a template that is still in use

How SendAPI Helps

SendAPI has a built-in template engine for dynamic HTML emails. A few details from the docs:

  • Standard variable syntax: templates use double curly braces, such as {{ name }}, in both the HTML body and the subject.
  • Opaque template IDs: every template has an ID in the form tmpl_xyaq57kye8ji, which you pass as template_id when sending.
  • A starter library: ten ready-made transactional templates are available to copy, covering welcome, verification, password reset, receipts, invoices, shipping, dunning, appointment reminders, trial expiry, and security alerts. A copied template is an ordinary template in your account, and later changes to the library never affect copies you have already made.
  • Managed through the API: you can list, create, get, update, and delete templates with the /v1/email/templates endpoints.
  • A warning worth noting: deleting a template takes effect immediately, and any integration that sends with that template ID will fail straight away with a 404 Not Found error.

Creating a template looks like this:

curl -X POST https://sendapi.co/v1/email/templates \
  -H "Authorization: Bearer sk_live_YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Password Reset",
    "subject": "Reset your password",
    "body_html": "<html><body>Hi {{ name }}, <a href=\"{{ reset_url }}\">Click here to reset</a>.</body></html>"
  }'

All of this comes with WhatsApp, SMS, OTP, and email under one API from $9.99 a month.