Skip to content
Skip to main content

Send email with reusable templates

Last updated:

You send the same shapes of email over and over: welcome notes, receipts, reminders. Coding that HTML into your app means a code change every time marketing tweaks the wording, and per-recipient personalization scattered through your send logic.

Nylas templates pull that content out of your code. You store a template with placeholders once, then render it with each recipient’s data and send the result, so the copy lives in one place and the personalization is a clean merge.

Send a POST /v3/templates request with a name, a subject, a body, and an engine of mustache. Use {{variable}} placeholders in the 2 fields, the subject and body, and Mustache fills them at render time. The example below stores a template with a {{user}} placeholder in both fields.

Templates come in 2 scopes: application-level templates at /v3/templates and grant-level templates at /v3/grants/{grant_id}/templates, so you can share copy across your app or scope it to one account.

Separately from the API’s hosted templates, the Nylas CLI keeps its own local templates on your machine for composing from the terminal. nylas email templates list shows them, and email templates use fills in variables and sends the result, so repeated emails don’t mean retyping the same body each time.

# List your local templates
nylas email templates list
# Render a template with variables and send it
nylas email templates use <template-id> --to [email protected] --var name=Ada
# Preview the rendered template without sending
nylas email templates use <template-id> --to [email protected] --var name=Ada --preview

CLI templates live in ~/.config/nylas/templates.json and aren’t synced with Nylas, so they’re a terminal convenience, not the API’s hosted templates. Pass each variable as --var key=value, and --to is required even with --preview. The composed message itself sends across all 6 providers. See the email templates list and email templates use command reference.

Render a stored template by calling POST /v3/templates/{template_id}/render with the values for its placeholders. Nylas returns 2 fields, the subject and body, with every {{variable}} replaced by your data. You then pass that rendered subject and body to the normal send endpoint, so the recipient gets a fully personalized message from the user’s own mailbox.

This split keeps templating and sending separate: render to preview or merge, then send when the content is ready.

A couple of details shape how you use templates. The engine is Mustache, so {{variable}} substitution works throughout the subject and body. By default rendering is strict, so a missing variable returns an error; set strict to false to render it empty instead. Both scopes render the same 2 fields, so keep the 2 scopes in mind: application-level templates are reused across grants, while grant-level ones belong to a single account.

Because rendering and sending are separate steps, you can render a template for a preview in your UI without sending anything, then send only when the user approves. See templates and workflows for the full reference.