Quick Start
Here’s how to create a template and send an email using it:EmailTemplate Struct
When sending emails with templates, use theEmailTemplate 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.
Creating Templates
Basic Template Creation
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.
Template Variables
Each variable in a template must be defined with theTemplateVariable 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.
Variable Types
- String Variables
- Number Variables
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.
Sending Emails with Templates
Using Template ID
Using Template Alias
You can use the template’s alias instead of its ID:Overriding Template Fields
You can override template defaults when sending:Fields specified in
SendEmailRequest take precedence over template defaults.Managing Templates
Retrieving a Template
Listing Templates
Updating a Template
Duplicating a Template
Deleting a Template
Common Use Cases
Welcome Emails
Welcome Emails
Order Confirmations
Order Confirmations
Password Reset
Password Reset
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