DEV Community

Qasim Muhammad
Qasim Muhammad

Posted on

Hosted Email Templates — Create, Render, and Send with Variable Substitution

The nylas template commands manage hosted email templates with variable substitution. Define a template once, render it with dynamic data, and send — no local files needed.

What hosted templates do

Templates are stored in Nylas and rendered server-side. Use {{variable}} placeholders for dynamic content (names, dates, URLs). Templates support HTML and plain text, with Mustache-style variable interpolation.

Quick Start

nylas template create \
  --name "welcome" \
  --subject "Welcome, {{name}}!" \
  --body "<h1>Hey {{name}}</h1><p>Your account is ready.</p>"

nylas email send \
  --to new-user@example.com \
  --template-id TPL_ID \
  --template-data '{"name": "Alice"}'
Enter fullscreen mode Exit fullscreen mode

Key commands

Command What it does
nylas template list List hosted templates
nylas template create --name N --subject S --body B Create a template
nylas template show <id> Show template details
nylas template update <id> Update a template
nylas template delete <id> --yes Delete a template
nylas template render <id> --data '{}' Preview rendered output
nylas template render-html --body H --engine mustache --data '{}' Render inline HTML

Rendering a preview before sending

nylas template render <template-id> \
  --data '{"name": "Bob", "company": "Acme", "link": "https://example.com/onboard"}'
Enter fullscreen mode Exit fullscreen mode

Outputs the fully-rendered HTML so you can verify before sending.

Sending with a template

nylas email send \
  --to customer@example.com \
  --template-id <id> \
  --template-data '{"name": "Alice", "invoice_url": "https://..."}'
Enter fullscreen mode Exit fullscreen mode

The subject line and body variables are both interpolated from the data JSON.

Local templates vs hosted templates

Feature Local (nylas email templates) Hosted (nylas template)
Storage On-disk files Nylas API (cloud)
Sharing Per-machine Per-application (all users)
Variables {{var}} in file {{var}} via API
Best for Personal scripts Team/product emails

Related posts


All commands: Nylas CLI Command Reference

Get started: brew install nylas/nylas-cli/nylasother install methods

Top comments (0)