import { Resend } from 'resend';
const resend = new Resend('re_xxxxxxxxx');
const { data, error } = await resend.templates.create({
name: 'order-confirmation',
html: '<p>Name: {{{PRODUCT}}}</p><p>Total: {{{PRICE}}}</p>',
variables: [
{
key: 'PRODUCT',
type: 'string',
fallbackValue: 'item',
},
{
key: 'PRICE',
type: 'number',
fallbackValue: 25,
}
],
});
// Or create and publish a template in one step
await resend.templates.create({ ... }).publish();
{
"id": "49a3999c-0ce1-4ea6-ab68-afcd6dc2e794",
"object": "template"
}
Create a new template with optional variables.
import { Resend } from 'resend';
const resend = new Resend('re_xxxxxxxxx');
const { data, error } = await resend.templates.create({
name: 'order-confirmation',
html: '<p>Name: {{{PRODUCT}}}</p><p>Total: {{{PRICE}}}</p>',
variables: [
{
key: 'PRODUCT',
type: 'string',
fallbackValue: 'item',
},
{
key: 'PRICE',
type: 'number',
fallbackValue: 25,
}
],
});
// Or create and publish a template in one step
await resend.templates.create({ ... }).publish();
{
"id": "49a3999c-0ce1-4ea6-ab68-afcd6dc2e794",
"object": "template"
}
"Your Name <sender@domain.com>".If provided, this value can be overridden when sending an email using the template.Hide properties
PRODUCT_NAME). The following variable names are reserved and cannot be used:
FIRST_NAME, LAST_NAME, EMAIL, RESEND_UNSUBSCRIBE_URL, contact, and this.'string' or 'number'import { Resend } from 'resend';
const resend = new Resend('re_xxxxxxxxx');
const { data, error } = await resend.templates.create({
name: 'order-confirmation',
html: '<p>Name: {{{PRODUCT}}}</p><p>Total: {{{PRICE}}}</p>',
variables: [
{
key: 'PRODUCT',
type: 'string',
fallbackValue: 'item',
},
{
key: 'PRICE',
type: 'number',
fallbackValue: 25,
}
],
});
// Or create and publish a template in one step
await resend.templates.create({ ... }).publish();
{
"id": "49a3999c-0ce1-4ea6-ab68-afcd6dc2e794",
"object": "template"
}
Was this page helpful?