Templates

Create reusable email templates with dynamic variables.

Creating Templates

Templates can be created in your dashboard or via the API:

POST https://getmailer.co/api/templates
{
  "name": "Welcome Email",
  "subject": "Welcome to {{company}}, {{name}}!",
  "html": "<h1>Hello {{name}}</h1><p>Thanks for joining {{company}}.</p>",
  "text": "Hello {{name}}, Thanks for joining {{company}}."
}

Template Variables

Use double curly braces for variables: {{variableName}}

Simple Variables

Hello {{name}}, your order #{{orderNumber}} is confirmed.

Default Values

Provide fallbacks for optional variables:

Hello {{name | default: 'there'}}

Using Templates

Reference a template by ID when sending an email:

curl -X POST https://getmailer.co/api/emails \
  -H "Authorization: Bearer gm_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "from": "[email protected]",
    "to": "[email protected]",
    "templateId": "tmpl_abc123",
    "variables": {
      "name": "John",
      "company": "Acme Inc",
      "orderNumber": "12345"
    }
  }'

Inline Variables

You can also use variables directly in your email content without a saved template:

curl -X POST https://getmailer.co/api/emails \
  -H "Authorization: Bearer gm_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "from": "[email protected]",
    "to": "[email protected]",
    "subject": "Hello {{name}}!",
    "html": "<h1>Welcome, {{name}}</h1><p>Your code is: {{code}}</p>",
    "variables": {
      "name": "John",
      "code": "ABC123"
    }
  }'

Variables work in subject, html, and text fields.

List Templates

GET https://getmailer.co/api/templates
{
  "templates": [
    {
      "id": "tmpl_abc123",
      "name": "Welcome Email",
      "subject": "Welcome to {{company}}, {{name}}!",
      "createdAt": "2024-01-10T10:00:00Z",
      "updatedAt": "2024-01-15T14:30:00Z"
    }
  ]
}

Update Template

PATCH https://getmailer.co/api/templates/:id
{
  "name": "Updated Welcome Email",
  "subject": "Welcome aboard, {{name}}!",
  "html": "<h1>Welcome {{name}}</h1><p>We're excited to have you!</p>"
}

Delete Template

DELETE https://getmailer.co/api/templates/:id

Returns 204 No Content on success.

Sequence Variables

When using templates in sequences, these built-in variables are automatically available:

VariableDescription
{{email}}Contact email address
{{firstName}} / {{first_name}}Contact first name
{{lastName}} / {{last_name}}Contact last name
{{sender_name}}Sender name (from sequence settings)
{{product_name}}Product name (from sequence settings)
{{booking_url}}Booking URL (from sequence settings)

Any custom fields stored on a contact are also available as variables. For example, if a contact has "company": "Acme" in their custom fields, you can use {{company}} in your templates.

Custom Fields

You can add custom fields to contacts that automatically become template variables. This allows you to personalize emails with any data you have about your contacts.

Adding Contacts with Custom Fields

When adding contacts via the API, include a customFields object:

curl -X POST https://getmailer.co/api/audiences/:id/contacts \
  -H "Authorization: Bearer gm_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "contacts": [{
      "email": "[email protected]",
      "firstName": "John",
      "lastName": "Doe",
      "customFields": {
        "company": "Acme Inc",
        "plan": "enterprise",
        "accountId": "ACC-12345",
        "signupSource": "webinar"
      }
    }]
  }'

Using Custom Fields in Templates

Custom fields are automatically available as template variables in sequences:

Hi {{firstName}}, welcome to {{company}}! Your account ID is {{accountId}}.

The variable name matches the custom field key exactly.

Example Use Cases

  • Company name: {{company}} - Personalize B2B emails
  • Plan tier: {{plan}} - Send plan-specific content
  • Referral code: {{referralCode}} - Include unique codes
  • Purchase date: {{purchaseDate}} - Reference order details
  • Custom URLs: {{dashboardUrl}} - Link to personalized pages

Tip: Custom fields can store any text value. Use them to segment contacts and create highly personalized email sequences based on user attributes, purchase history, or engagement data.

Conditional Content

Show or hide content based on contact data using conditional blocks. This allows you to create dynamic emails that adapt to each recipient.

Simple Conditionals

Show content only if a field exists and has a value:

{{#if company}}
  <p>We're excited to work with {{company}}!</p>
{{/if}}

If/Else Blocks

Provide alternative content when a condition is not met:

{{#if firstName}}
  Hi {{firstName}},
{{else}}
  Hi there,
{{/if}}

Value Comparisons

Check if a field equals a specific value:

{{#if plan == "enterprise"}}
  <p>As an Enterprise customer, you have access to priority support.</p>
{{else}}
  <p>Upgrade to Enterprise for priority support.</p>
{{/if}}

{{#if plan != "free"}}
  <p>Thank you for being a paying customer!</p>
{{/if}}

Practical Example

A complete email with multiple conditionals:

{{#if firstName}}Hi {{firstName}}{{else}}Hi there{{/if}},

Thank you for signing up{{#if company}} on behalf of {{company}}{{/if}}!

{{#if plan == "pro"}}
You're on our Pro plan with access to all features.
{{/if}}

{{#if plan == "free"}}
Consider upgrading to Pro for advanced features.
{{/if}}

{{#if bookingUrl}}
Book a demo call: {{bookingUrl}}
{{/if}}

Best,
{{sender_name}}

Note: Conditionals work in sequences and broadcasts. The comparison is case-insensitive, so plan == "Pro" will match "pro", "Pro", or "PRO".

Related