NevarMail

Templates

Create, manage, and render reusable email templates with variable substitution.

NevarMail templates let you create reusable email content with variable placeholders. Templates support versioning, validation, and preview rendering.

Create a template

POST /api/templates
{
  "name": "Welcome Email",
  "subject": "Welcome, {{user.name}}!",
  "htmlTemplate": "<h1>Hello {{user.name}}</h1><p>Welcome to {{company.name}}.</p>",
  "textTemplate": "Hello {{user.name}}. Welcome to {{company.name}}.",
  "variables": [
    { "name": "user.name", "type": "string", "required": true },
    { "name": "company.name", "type": "string", "required": true }
  ],
  "category": "onboarding"
}

Template fields

FieldTypeRequiredDescription
namestringYesTemplate name
subjectstringYesSubject line (supports {{variables}})
htmlTemplatestringNoHTML body (supports {{variables}})
textTemplatestringNoPlain text body (supports {{variables}})
variablesarrayNoVariable declarations
categorystringNoTemplate category for organization

Variable declarations

Each variable in the variables array has:

FieldTypeRequiredDescription
namestringYesVariable name (e.g., user.name)
typestringYesVariable type (string, number, etc.)
requiredbooleanNoWhether the variable must be provided
defaultanyNoDefault value if not provided

List templates

GET /api/templates

Query parameters

ParameterTypeDescription
categorystringFilter by category
isActivestring"true" or "false" to filter by status
searchstringSearch templates by name

Get a template

GET /api/templates/:id

Update a template

PUT /api/templates/:id
{
  "subject": "Welcome aboard, {{user.name}}!",
  "htmlTemplate": "<h1>Welcome aboard, {{user.name}}</h1>"
}

Updates automatically increment the template version number.

Delete a template

DELETE /api/templates/:id

Returns { "deleted": true } on success.

Validate a template

Check a template for variable declaration mismatches before sending.

POST /api/templates/:id/validate
{
  "valid": true,
  "errors": [],
  "warnings": ["Variable \"foo\" is declared but never used in template"],
  "variables": ["user.name", "company.name"]
}
  • Errors: A {{variable}} is used in the template but not declared
  • Warnings: A variable is declared but never referenced in the template

Render a template

Preview a template with variable values without sending an email.

POST /api/templates/:id/render
{
  "variables": {
    "user": { "name": "Jane" },
    "company": { "name": "Acme" }
  }
}
{
  "html": "<h1>Hello Jane</h1><p>Welcome to Acme.</p>",
  "text": "Hello Jane. Welcome to Acme.",
  "subject": "Welcome, Jane!"
}

Variable syntax

Templates use double-brace syntax for variable interpolation: {{variable.name}}. Variables support dot notation for nested values:

  • {{user.name}} -- resolves to the name property of the user context
  • {{company.address.city}} -- resolves to a deeply nested value

See Sending Email for how to send templated emails with variable values.

On this page