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.
Copy
Ask AI
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, }, },});
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.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.
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).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.
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.
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.For a more streamlined flow, create and publish a template in a single step.
Node.js
Copy
Ask AI
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.
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.
Copy
Ask AI
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, }, },});
You can also duplicate an existing Template in the dashboard or via the API.
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.
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.