Using Templates | SMTP Express - The Express Emailing Experience for Developers and Businesses


Using Templates

While you can absolutely send custom html in your requests to the send API, there can be some drawbacks like having to manage the html from your codebase, or suffering for the overhead that comes with that. To solve this, you can create your email html directly from your project dashboard and use template variables to inject dynamic content into your template.

To create a template, navigate to the Templates menu from your project dashboard and click on the New Template button. To create a template variable, open the template you just created and click on the Variables tab.

Using template variables

So let's say you've started working on an email template to notify your users of an activity on their account, you can make a strong impression by starting with a personalized greeting by having their names as a variable. Using SMTP Express, this is what that looks like.

   <h1> Hi there {{variableId}} </h1>

Sending an email using a template

This works by replacing the message parameter with the template object as seen in the snippet below.

1// npm install smtpexpress
2import { createClient } from "smtpexpress"
3const smtpexpressClient = createClient({...});
6  subject: "A message from the express",
7  template: {
8    id: "example-template-id",
9    variables: {
10      variableId: "variableValue"
11    }
12  },
13  sender: {
14    name: "Tenotea",
15    email: ""
16  },
17  recipients: {
18    name: "My recipient's name", 
19    email: ""
20  }

Template Parameters

Descriptions for the send API request parameters can be found under the send api docs.



Id *


The ID of the template. Can be found on the template's overview tab.



A key-value pair of your template variable ids, and their dynamic values