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.
<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 -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:
- The API looks up the template by
templateKeyortemplateId - It verifies the template belongs to the authenticated user
- The template's
subjectandbodyare rendered with the providedvariables - 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
| Feature | Raw HTML | Template |
|---|---|---|
| Content provided in request | Yes | No |
| Stored on server | No | Yes |
| Dynamic variables | Yes | Yes |
| Reusable across sends | Manual | Yes |
| Editable without code changes | No | Yes |
Both raw HTML and templates support {{variable}} interpolation.
Interpolation is handled by the core engine at send time.
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
- Sending Emails — More sending options
- API Reference — Full endpoint docs