Command Palette

Search for a command to run...

Guide

Email Templates

Learn how to create and use reusable email templates with dynamic variables for personalized email content.

Why Use Templates?

Consistency - Maintain brand consistency across all emails

Efficiency - Write once, use many times

Personalization - Dynamic variables for each recipient

Easy Updates - Change template once, affects all future emails

Creating a Template

Create a template with dynamic variables using double curly braces:

cURL
curl -X POST https://www.unosend.co/api/v1/templates \
  -H "Authorization: Bearer un_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Welcome Email",
    "subject": "Welcome to {{company_name}}, {{first_name}}!",
    "html": "<!DOCTYPE html><html><body><h1>Welcome, {{first_name}}!</h1><p>Thanks for joining {{company_name}}.</p><a href=\"{{dashboard_url}}\">Go to Dashboard</a></body></html>",
    "text": "Welcome, {{first_name}}! Thanks for joining {{company_name}}. Visit: {{dashboard_url}}"
  }'

Response

response.json
{
  "id": "tpl_xxxxxxxxxxxxxxxx",
  "name": "Welcome Email",
  "subject": "Welcome to {{company_name}}, {{first_name}}!",
  "variables": ["company_name", "first_name", "dashboard_url"],
  "created_at": "2024-01-15T10:30:00Z"
}

Variable Syntax

Templates support various variable features:

Basic Variables

basic-variables.html
Hello, {{first_name}}!
Your email is: {{email}}

Default Values

default-values.html
Hello, {{first_name | default: "there"}}!
Your plan: {{plan | default: "Free"}}

Conditional Content

conditionals.html
{{#if is_premium}}
<div class="premium-badge">Premium Member</div>
{{/if}}

{{#if has_items}}
<h2>Your Items</h2>
{{else}}
<p>No items yet. Start shopping!</p>
{{/if}}

Loops

loops.html
<h2>Your Order</h2>
<table>
  {{#each items}}
  <tr>
    <td>{{name}}</td>
    <td>{{quantity}}</td>
    <td>{{price}}</td>
  </tr>
  {{/each}}
</table>
<p>Total: {{total}}</p>

Sending Emails with Templates

Use template_id instead of html when sending:

cURL
curl -X POST https://www.unosend.co/api/v1/emails \
  -H "Authorization: Bearer un_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "from": "hello@yourdomain.com",
    "to": ["john@example.com"],
    "template_id": "tpl_xxxxxxxxxxxxxxxx",
    "variables": {
      "first_name": "John",
      "company_name": "Acme Inc",
      "dashboard_url": "https://app.acme.com/dashboard",
      "is_premium": true
    }
  }'

Batch Sending with Templates

Send personalized emails to multiple recipients efficiently using the batch endpoint:

cURL
curl -X POST https://www.unosend.co/api/v1/emails/batch \
  -H "Authorization: Bearer un_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "emails": [
      {
        "from": "hello@yourdomain.com",
        "to": ["john@example.com"],
        "template_id": "tpl_xxxxxxxxxxxxxxxx",
        "variables": {
          "first_name": "John",
          "plan": "Pro"
        }
      },
      {
        "from": "hello@yourdomain.com",
        "to": ["jane@example.com"],
        "template_id": "tpl_xxxxxxxxxxxxxxxx",
        "variables": {
          "first_name": "Jane",
          "plan": "Free"
        }
      }
    ]
  }'

Common Template Examples

Order Confirmation

order-confirmation.html
<h1>Order Confirmed!</h1>
<p>Hi {{customer_name}},</p>
<p>Thanks for your order #{{order_number}}.</p>

<h2>Order Details</h2>
<table>
  <tr>
    <th>Item</th>
    <th>Qty</th>
    <th>Price</th>
  </tr>
  {{#each items}}
  <tr>
    <td>{{name}}</td>
    <td>{{quantity}}</td>
    <td>{{price}}</td>
  </tr>
  {{/each}}
</table>

<p><strong>Total: {{total}}</strong></p>
<p>Shipping to: {{shipping_address}}</p>

Password Reset

password-reset.html
<h1>Reset Your Password</h1>
<p>Hi {{first_name | default: "there"}},</p>
<p>We received a request to reset your password.</p>

<a href="{{reset_url}}" 
   style="display: inline-block; padding: 12px 24px; 
          background: #000; color: #fff; text-decoration: none; 
          border-radius: 6px;">
  Reset Password
</a>

<p style="margin-top: 20px; color: #666; font-size: 13px;">
  This link will expire in {{expiry_hours}} hours.
</p>

<p style="color: #666; font-size: 12px;">
  If you didn't request this, please ignore this email.
</p>

Managing Templates

Update a Template

cURL
curl -X PATCH https://www.unosend.co/api/v1/templates/tpl_xxxxxxxx \
  -H "Authorization: Bearer un_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "subject": "Welcome aboard, {{first_name}}!",
    "html": "<h1>Updated welcome content</h1>"
  }'

List Templates

cURL
curl https://www.unosend.co/api/v1/templates \
  -H "Authorization: Bearer un_your_api_key"

Get a Template

cURL
curl https://www.unosend.co/api/v1/templates/tpl_xxxxxxxx \
  -H "Authorization: Bearer un_your_api_key"

Delete a Template

cURL
curl -X DELETE https://www.unosend.co/api/v1/templates/tpl_xxxxxxxx \
  -H "Authorization: Bearer un_your_api_key"