← Back to docs
Email Templates
Email Templates
Templates allow you to create reusable email designs with dynamic content. Define your templates once, then send personalized emails by passing variables.
Creating Templates
Via Dashboard
- Go to Templates in the dashboard
- Click Create Template
- Enter a template name and unique slug
- Design your template using the HTML editor
- Add variables using
{{variable_name}}syntax - Click Save Template
Via API
curl -X POST https://api.postscale.io/v1/templates \
-H "Authorization: Bearer ps_live_your_api_key" \
-H "Content-Type: application/json" \
-d '{
"name": "Welcome Email",
"slug": "welcome",
"subject": "Welcome to {{company_name}}, {{first_name}}!",
"html_body": "<h1>Hello {{first_name}}</h1><p>Welcome to {{company_name}}!</p>",
"text_body": "Hello {{first_name}}, Welcome to {{company_name}}!"
}'
Template Variables
Use double curly braces to define variables:
<h1>Hello {{first_name}}</h1>
<p>Your order #{{order_id}} has been confirmed.</p>
<p>Total: {{currency}}{{total}}</p>
Variable Types
| Type | Example | Description |
|---|---|---|
| String | {{name}} | Simple text replacement |
| Object | {{user.name}} | Access nested properties |
| Array | {{items[0].name}} | Access array elements |
Conditional Content
Use conditionals for dynamic sections:
{{#if premium_user}}
<p>Thank you for being a premium member!</p>
{{else}}
<p>Upgrade to premium for exclusive benefits.</p>
{{/if}}
Loops
Iterate over arrays:
<h2>Your Order</h2>
<ul>
{{#each items}}
<li>{{this.name}} - {{this.price}}</li>
{{/each}}
</ul>
Sending with Templates
Using Template Slug
await postscale.emails.send({
from: 'orders@yourapp.com',
to: 'customer@example.com',
template: 'order-confirmation',
variables: {
first_name: 'Jane',
order_id: '12345',
items: [
{ name: 'Widget', price: '$29.99' },
{ name: 'Gadget', price: '$49.99' },
],
total: '79.98',
currency: '#x27;,
},
});
Using Template ID
await postscale.emails.send({
from: 'orders@yourapp.com',
to: 'customer@example.com',
template_id: 'tmpl_abc123',
variables: {
first_name: 'Jane',
// ...
},
});
Default Variables
Set default values for variables using the default helper:
<p>Hello {{default first_name "there"}}</p>
If first_name is not provided, it defaults to "there".
Built-in Variables
These variables are automatically available:
| Variable | Description |
|---|---|
{{current_year}} | Current year (e.g., 2026) |
{{current_date}} | Current date in ISO format |
{{unsubscribe_url}} | Unsubscribe link |
Template Testing
Preview with Variables
curl -X POST https://api.postscale.io/v1/templates/welcome/preview \
-H "Authorization: Bearer ps_live_your_api_key" \
-d '{
"variables": {
"first_name": "Jane",
"company_name": "Acme Corp"
}
}'
Returns the rendered subject, HTML, and text with variables substituted.
Test before deploying
Always preview your template with test variables before deploying template changes to production.
Template Versioning
Coming soon. Template versioning will allow you to save multiple versions of a template, pin sends to specific versions, and roll back safely.
Best Practices
- Use descriptive slugs:
order-confirmationnottemplate-1 - Include plain text: Always provide a text version for email clients that don't support HTML
- Test across clients: Check your templates in Gmail, Outlook, Apple Mail, etc.
- Keep it simple: Avoid complex layouts that may break in different email clients
- Use inline styles: Email clients strip
<style>tags; use inline CSS instead