Mailzeno LogomailzenoDocs

Templates

Mailzeno supports stored email templates with dynamic {{variable}} placeholders. Templates let you separate your email content from your application code and manage it through the dashboard.

Creating templates

Templates are created and managed through the Mailzeno Dashboard. Each template has a name, key, subject, and HTML body. Use {{variable}} placeholders for dynamic content.

Template HTML
<div style="font-family: sans-serif; max-width: 600px; margin: 0 auto;">
<h1>Welcome, {{name}}!</h1>
<p>Thanks for joining {{company}}.</p>
<p>Your account is ready at {{dashboard_url}}</p>
</div>

Sending with templates

Via template key

import { MailZeno } from "@mailzeno/client"

const mz = new Mailzeno(process.env.MAILZENO_API_KEY!)

await mz.emails.send({
smtpId: "your_smtp_id",
from: "you@example.com",
to: "user@example.com",
templateKey: "welcome_email",
variables: {
  name: "Harsh",
  company: "Mailzeno",
  dashboard_url: "https://mailzeno.dev/dashboard",
},
})

Via template ID

await mz.emails.send({
smtpId: "your_smtp_id",
from: "you@example.com",
to: "user@example.com",
templateId: "550e8400-e29b-41d4-a716-446655440000",
variables: {
  name: "Harsh",
},
})

Via REST API

cURL
curl -X POST https://api.mailzeno.dev/v1/emails \
-H "Authorization: Bearer mz_api_your_api_key" \
-H "Content-Type: application/json" \
-d '{
  "smtpId": "your_smtp_id",
  "from": "you@example.com",
  "to": "user@example.com",
  "templateKey": "welcome_email",
  "variables": {
    "name": "Harsh",
    "company": "Mailzeno",
    "dashboard_url": "https://mailzeno.dev/dashboard"
  }
}'

Template resolution

When you send an email with a template:

  1. The API looks up the template by templateKey or templateId
  2. It verifies the template belongs to the authenticated user
  3. The template's subject and body are rendered with the provided variables
  4. The rendered content is sent through the SMTP engine

Variables are replaced at send time. If a variable is not provided, it renders as an empty string.

Template vs raw HTML

FeatureRaw HTMLTemplate
Content provided in requestYesNo
Stored on serverNoYes
Dynamic variablesYesYes
Reusable across sendsManualYes
Editable without code changesNoYes
Variable support

Both raw HTML and templates support {{variable}} interpolation. Interpolation is handled by the core engine at send time.

Content rule

You must provide either html content OR a templateKey/templateId — not both. The SDK enforces this at the type level using discriminated unions.

Managing templates

Templates can be managed through the Mailzeno Dashboard:

  • Template Key — A human-readable identifier (e.g., welcome_email, password_reset)
  • Template ID — A UUID auto-generated on creation
  • Create, edit, delete — Full CRUD through the dashboard UI

Next steps