Skip to main content
Templates API is currently in private beta and only available to a limited number of users. APIs might change before GA.To use the methods on this page, you must upgrade your Resend Node SDK to version resend@https://pkg.pr.new/resend/resend-node/resend@cb04015 or later.Get in touch if you're interested in testing this feature.
Using email templates, you can define the structure and layout of a message. You can include custom variables that will be replaced with the actual values when sending the email. Templates can be used in a variety of email types:
  • Login/Auth
  • Onboarding
  • Ecommerce
  • Notifications
  • Newsletters

Add a template

There are two ways to add a template:
  1. Add a template in the dashboard
  2. Import an HTML or React Email file
  3. Create a template by using the API

Add a template in the dashboard

The Templates dashboard shows all existing templates. Add a template Click Create template to start a new template. Create or import a template The no-code editor allows you to create an email template using a visual editor. To add a variable, select Variable in the commands palette or type {{ in the editor. variable dropdown

Import an HTML or React Email file

You can also import an HTML or React Email file to create a template from your existing code. After importing, you can edit the template in the no-code editor and add variables as needed. import html

Create a template by using the API

Finally, programmatically create a template by using the API. The payload can optionally include variables to be used in the template.
import { Resend } from 'resend';

const resend = new Resend('re_xxxxxxxxx');

await resend.templates.create({
  name: 'welcome-email',
  html: '<strong>Hey, {{{NAME}}}, you are {{{AGE}}} years old.</strong>',
  variables: [
    {
      key: 'NAME',
      type: 'string',
      fallbackValue: 'user',
    },
    {
      key: 'AGE',
      type: 'number',
      fallbackValue: 25,
    },
    {
      key: 'OPTIONAL_VARIABLE',
      type: 'string',
    },
  ],
});
View the API reference for more details.

Duplicate a template

You can also duplicate an existing template in the dashboard or via the API. Duplicate a template

Publish a template

By default, templates are in a draft state. To use a template to send emails, you must first publish it via the dashboard or via the API. Publish a template Once a template is published, you can continue to edit it without impacting existing emails sent using the template. Only after publishing again will the changes be reflected in emails using the template.

Adding variables

Resend supports both contact and custom variables. Each template may contain up to 20 variables. variable dropdown Contact variables are automatically available in all templates and include:
  • {{{FIRST_NAME|fallback}}}
  • {{{LAST_NAME|fallback}}}
  • {{{EMAIL}}}
Custom variables are defined when creating a template. To add a custom variable, select Variable in the commands palette or type {{ in the editor. Define the name, type, and fallback_value (optional). variable dropdown You can also define custom variables via the API. The payload can optionally include variables to be used in the template. Each variable is an object with the following properties:
  • key: The key of the variable. We recommend capitalizing the key. (e.g. FIRST_NAME).
  • type: The type of the variable. Possible values: 'string', 'number', 'boolean', 'object', and 'list'.
  • fallback_value: The fallback value of the variable. If no fallback value is provided, you must provide a value for the variable when sending an email using the template. object and list types must include a fallback_value.
See the API reference for more details.

Delete a template

You can delete a template via the dashboard by clicking on the Delete button or via the API. Delete a template

Using templates in transactional emails

When sending an email using a template, the template variables will be replaced with the actual values. Both the /emails and /emails/batch endpoints support templates.
cURL
curl -X POST 'https://api.resend.com/emails' \
     -H 'Authorization: Bearer re_xxxxxxxxx' \
     -H 'Content-Type: application/json' \
     -d $'{
  "from": "Acme <onboarding@resend.dev>",
  "to": ["delivered@resend.dev"],
  "subject": "hello world",
  "template" : {
    "id": "f3b9756c-f4f4-44da-bc00-9f7903c8a83f",
    "variables": {
      "NAME": "John"
    }
  }
}'
Learn more about sending emails or sending batch emails with templates via the API.

Validation errors

When sending an email using a template, the template variables will be replaced with the actual values. If a variable is not provided, the fallback value will be used. If no fallback value is provided, the email will not be sent and a validation error will be returned. See the API reference for more details or the errors reference.
I