Skip to main content
Email templates allow you to create reusable email designs with dynamic variables that can be populated at send time.

Quick Start

Here’s how to create a template and send an email using it:

EmailTemplate Struct

When sending emails with templates, use the EmailTemplate struct:
string
required
The template ID or alias to use for this email.
map[string]any
Key-value pairs to populate the template placeholders. Values can be strings, numbers, or other JSON-serializable types.
Source: emails.go:17

Creating Templates

Basic Template Creation

Source: examples/send_email_with_template.go:17

CreateTemplateRequest Fields

string
required
The name of the template.
string
A unique alias for the template. Use this to reference the template instead of its ID.
string
Default sender email address for this template.
string
Default subject line. Can include template variables like {{{variableName}}}.
any
Default reply-to address. Can be a string or array of strings.
string
required
HTML content with template variables. Use triple braces {{{variableName}}} for variables.
string
Plain text version with template variables.
[]*TemplateVariable
Array of variable definitions used in the template.
All variables referenced in Html or Subject (e.g., {{{userName}}}) must be declared in the Variables array, or the API will return a validation error.
Source: templates.go:28

Template Variables

Each variable in a template must be defined with the TemplateVariable struct:
string
required
The variable name (without braces). Must match the placeholder in HTML/subject.
VariableType
required
Variable type: VariableTypeString or VariableTypeNumber.
any
Default value used if no value is provided when sending the email.
Source: templates.go:19

Variable Types

Use for: names, email addresses, text content, URLs

Publishing Templates

Templates must be published before they can be used:
Only published templates can be used to send emails. Unpublished templates are in draft state.
Source: examples/send_email_with_template.go:58

Sending Emails with Templates

Using Template ID

Source: examples/send_email_with_template.go:65

Using Template Alias

You can use the template’s alias instead of its ID:
Using aliases makes your code more maintainable since you don’t need to update IDs when recreating templates.
Source: examples/send_email_with_template.go:84

Overriding Template Fields

You can override template defaults when sending:
Source: examples/send_email_with_template.go:103
Fields specified in SendEmailRequest take precedence over template defaults.

Managing Templates

Retrieving a Template

Listing Templates

Updating a Template

After updating a template, you must publish it again for changes to take effect in sent emails.

Duplicating a Template

Deleting a Template

Source: examples/send_email_with_template.go:126

Common Use Cases

Best Practices

1

Declare All Variables

Always declare variables in the Variables array before using them in HTML:
2

Use Aliases for Stability

Use template aliases instead of IDs for better code maintainability:
3

Provide Fallback Values

Always provide sensible fallback values for optional variables:
4

Use Triple Braces

Use triple braces {{{variable}}} for template variables to prevent HTML escaping:
5

Publish After Updates

Remember to publish templates after creating or updating them:

Next Steps

Sending Emails

Learn the basics of sending emails

Attachments

Add attachments to template emails

Batch Emails

Send templated emails in bulk

Scheduled Emails

Schedule template emails for later