Email templates with variables

Updated on

A template keeps HTML out of your code. You write it once in the dashboard, then only send the variables.

Create a template

  1. Open Templates and create a template.
  2. Fill in the subject, the HTML body and, if you want, a plain-text version.
  3. Check the rendering by entering sample variables in Preview variables (JSON).

Syntax

  • {{ first_name }}: inserts the value (escaped in HTML).
  • {{ customer.first_name }}: reads a field of an object.
  • {{ first_name | there }}: default value when the variable is empty.
  • {{{ html_block }}}: inserts HTML as-is, without escaping.
Subject: Your order {{ order.number }}
HTML   : <p>Hi {{ customer.first_name | there }},</p>
         <p>Your order {{ order.number }} has shipped.</p>

Send with a template

curl https://smapiz.com/v1/messages \
  -H "Authorization: Bearer smz_live_..." \
  -H "Content-Type: application/json" \
  -d '{
    "mailbox_id": "mbx_...",
    "to": "[email protected]",
    "template_id": "tpl_...",
    "variables": {
      "customer": { "first_name": "Ada" },
      "order": { "number": "1042" }
    }
  }'

If you also pass subject, html or text in the request, they override the template’s.

Next guideAPI keys, permissions and team