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
| Field | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Template name |
subject | string | Yes | Subject line (supports {{variables}}) |
htmlTemplate | string | No | HTML body (supports {{variables}}) |
textTemplate | string | No | Plain text body (supports {{variables}}) |
variables | array | No | Variable declarations |
category | string | No | Template category for organization |
Variable declarations
Each variable in the variables array has:
| Field | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Variable name (e.g., user.name) |
type | string | Yes | Variable type (string, number, etc.) |
required | boolean | No | Whether the variable must be provided |
default | any | No | Default value if not provided |
List templates
GET /api/templatesQuery parameters
| Parameter | Type | Description |
|---|---|---|
category | string | Filter by category |
isActive | string | "true" or "false" to filter by status |
search | string | Search templates by name |
Get a template
GET /api/templates/:idUpdate 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/:idReturns { "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 thenameproperty of theusercontext{{company.address.city}}-- resolves to a deeply nested value
See Sending Email for how to send templated emails with variable values.