Skip to main content
Templates are stored on Resend and can be referenced when you send transactional emails. With Templates, define the structure and layout of a message and optionally include custom variables which will be replaced with the actual values when sending the email. Send only the Template id and variables (instead of sending the HTML), and Resend will render your final email and send it out.
import { Resend } from 'resend';

const resend = new Resend('re_xxxxxxxxx');

await resend.emails.send({
  from: 'Acme <onboarding@resend.dev>',
  to: 'delivered@resend.dev',
  template: {
    id: 'order-confirmation',
    variables: {
      PRODUCT: 'Vintage Macintosh',
      PRICE: 499,
    },
  },
});
Use Templates for transactional emails like:
  • Login/Auth
  • Onboarding
  • Ecommerce
  • Notifications
  • Automations

Add a Template

You can add a Template:

Add a Template in the dashboard

The Templates dashboard shows all existing templates. Click Create template to start a new Template. Add a template

Add a Template from an existing email

You can create a Template from an existing Broadcast. Locate your desired Broadcast in the Broadcast dashboard, click the more options button , and choose Clone as template. Add a template from an existing email You can also import an HTML or React Email file to create a Template from your existing code. Create a new Template, then paste or drag in your HTML or React Email content.

Create a Template by using the API

You can also 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: 'order-confirmation',
  from: 'Resend Store <store@resend.com>',
  subject: 'Thanks for your order!',
  html: '<p>Name: {{{PRODUCT}}}</p><p>Total: {{{PRICE}}}</p>',
  variables: [
    {
      key: 'PRODUCT',
      type: 'string',
      fallbackValue: 'item',
    },
    {
      key: 'PRICE',
      type: 'number',
      fallbackValue: 20,
    },
  ],
});
View the API reference for more details.

Add Variables

Each Template may contain up to 20 variables. 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 following variable names are reserved and cannot be used: FIRST_NAME, LAST_NAME, EMAIL, UNSUBSCRIBE_URL, contact,this.
Learn more about working with variables.

Send Test Emails

You can send test emails to your inbox to preview your Template before sending it to your audience. Provide variable values to test the rendered Template in your inbox.

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 For a more streamlined flow, create and publish a template in a single step.
Node.js
await resend.templates.create({ ... }).publish();
Once a Template is published, you can continue to edit it without impacting existing emails sent using the Template. As you work, your changes are saved as a draft, although you can also manually save drafts by pressing Cmd + S (Mac) or Ctrl + S (Windows). Only after publishing again will the changes be reflected in emails using the Template. Learn more about Template version history.

Send Emails with Templates

When sending a transactional email, you can reference your Template and include your variables in the call. The Template variables will be replaced with the actual values.
import { Resend } from 'resend';

const resend = new Resend('re_xxxxxxxxx');

await resend.emails.send({
  from: 'Acme <onboarding@resend.dev>',
  to: 'delivered@resend.dev',
  template: {
    id: 'order-confirmation',
    variables: {
      PRODUCT: 'Vintage Macintosh',
      PRICE: 499,
    },
  },
});
Learn more about sending emails or sending batch emails with Templates via the API.

Duplicate a Template

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

You can create a Template from an existing Broadcast. Locate your desired Broadcast in the Broadcast dashboard, click the more options button, and choose Clone as template.

Delete a Template

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

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.