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

Documentation

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({...});
4
5smtpexpressClient.sendApi.sendMail({
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: "tenotea@smtpexpress.com"
16  },
17  recipients: {
18    name: "My recipient's name", 
19    email: "recipient@recipients.com"
20  }
21});

Template Parameters

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

Template

Object

Id *

String

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

Variables

Object

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