Templates
Store an email's HTML, subject and sender as a template with variables, publish it, then edit a draft without touching the published version. Create, update, duplicate and delete templates by id or alias.
A template keeps the parts of an email you send again and again: its HTML, plain text,
subject, sender and reply-to, with variables such as {{{PRODUCT}}} where each email puts its
own values. The templates API is Resend's: the same endpoints, fields and answers, so a Resend
SDK pointed at exx.sh manages your templates too.
A template has a draft, which you create and edit, and once you publish it a published version. Only the published version is used for sending, so you can keep editing the draft without changing what your emails look like until you publish again.
Create a template
Create it with POST /templates. name and
html are required:
curl -X POST https://api.exx.sh/templates \
-H "Authorization: Bearer $EXX_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "Order confirmation",
"alias": "order-confirmation",
"from": "Acme <orders@acme.com>",
"subject": "Your {{{PRODUCT}}} is on its way",
"html": "<p>Thanks for buying {{{PRODUCT}}}. Total: {{{PRICE}}}</p>",
"variables": [
{ "key": "PRODUCT", "type": "string", "fallback_value": "order" },
{ "key": "PRICE", "type": "number" }
]
}'The answer is the template's id:
{ "object": "template", "id": "01a1b246-b422-7615-a9b9-09d31765fc52" }With the TypeScript SDK:
import { Exx } from "@exx.sh/sdk";
const exx = new Exx(process.env.EXX_API_KEY);
const { data, error } = await exx.templates.create({
name: "Order confirmation",
alias: "order-confirmation",
subject: "Your {{{PRODUCT}}} is on its way",
html: "<p>Thanks for buying {{{PRODUCT}}}. Total: {{{PRICE}}}</p>",
variables: [
{ key: "PRODUCT", type: "string", fallbackValue: "order" },
{ key: "PRICE", type: "number" },
],
});| Field | Required | Value |
|---|---|---|
name | yes | Your name for it, up to 255 characters |
html | yes | The HTML body, with variables |
alias | no | Another way to name it in the API, below |
from | no | The sender, orders@acme.com or Acme <orders@acme.com> |
subject | no | The subject line, with variables; one line, as an email's subject |
reply_to | no | One address or an array of up to 50 |
text | no | The plain-text body, with variables; leave it out to have it made from the HTML when an email is sent (also when it renders empty), or give "" for no plain-text part |
variables | no | The variables the template uses, below |
html, subject and text together are up to 1 MiB. A project
keeps up to 500 templates.
Variables
A variable is a name between triple braces: {{{PRODUCT}}}. Names use ASCII letters, digits
and _ (up to 50 characters) and are case-sensitive. Variables
work in html, subject and text; a template has up to
50 of them.
Declare every variable you use in variables:
| Field | Value |
|---|---|
key | The variable's name |
type | string or number |
fallback_value | Optional: the value used when an email gives none, of the variable's type (a string of up to 2,000 characters, or a number) |
A variable that is used but not declared is refused, naming it:
html: `{{{PRICE}}}` is not declared in `variables`exx.sh also takes a fallback right in the tag, {{{NAME|there}}}: that use takes there
when no value is given. A variable whose every use in a part has such a fallback needs no
declaration. Values are written into the HTML escaped, so a value such as <b> shows as
text; keep attributes that hold a variable quoted (href="{{{URL}}}").
Contact values and the unsubscribe link
A template can use the values of the person it goes to, without declaring them: exx.sh fills them from the contact of that address in your project when the email has one recipient (to, cc and bcc together).
| In the template | Becomes |
|---|---|
{{{contact.first_name}}}, {{{FIRST_NAME}}} | the contact's first name |
{{{contact.last_name}}}, {{{LAST_NAME}}} | the contact's last name |
{{{contact.email}}}, {{{EMAIL}}} | the contact's address |
{{{contact.plan}}} | the contact's value of the property plan, else the property's fallback value |
{{{RESEND_UNSUBSCRIBE_URL}}} (also UNSUBSCRIBE_URL, EXX_UNSUBSCRIBE_URL) | the contact's own unsubscribe link |
When there is no contact, or no value, the tag's fallback is used:
{{{contact.first_name|there}}}. Without either, the send is refused and names the tag:
template: no value for `{{{EMAIL}}}`: a template send takes it from the contact of its one recipient in the project, else from the tag's fallbackThe unsubscribe link opens a page where the person can unsubscribe in one click; it sets
the contact's unsubscribed and does not add the address to your suppressions. An email
that carries it also gets the List-Unsubscribe and List-Unsubscribe-Post headers, so
mailbox providers show their own unsubscribe button. Since one link would unsubscribe one
person for everyone, a template with the link sends only to one recipient at a time.
You cannot pass these names in template.variables, nor declare them. {{{this}}}, and
{{{contact}}} without a key, are refused when the template is saved.
Publish
A new template is a draft ("status": "draft"). Publish it with
POST /templates/{id}/publish:
curl -X POST https://api.exx.sh/templates/order-confirmation/publish \
-H "Authorization: Bearer $EXX_API_KEY"Its status is then published, with the time in published_at.
Send with a template
Send a published template with template on POST /emails
or in a batch: its id (or alias) and a value for each variable,
a string or a number:
curl -X POST https://api.exx.sh/emails \
-H "Authorization: Bearer $EXX_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"to": "delivered@acme.com",
"template": {
"id": "order-confirmation",
"variables": { "PRODUCT": "Laptop", "PRICE": 1299.5 }
}
}'With the TypeScript SDK:
const { data, error } = await exx.emails.send({
to: "delivered@acme.com",
template: { id: "order-confirmation", variables: { PRODUCT: "Laptop", PRICE: 1299.5 } },
});- The email takes the template's
from,subjectandreply_to; give any of them in the request to use yours instead (asubjectyou give is used as written, without variables). Without one in the template,fromandsubjectare required as usual, andfrommust be on a verified domain of the project. htmlandtextcannot be given withtemplate. The plain-text part is the template'stext, or is made from its HTML when the template has none or it renders empty; a template whosetextis""sends no plain-text part.- Each use of a variable takes the value you give, else the tag's own fallback
(
{{{NAME|there}}}), else the declaredfallback_value. Numbers are written as given (25,9.99). Values you give for variables the template does not use are ignored. - Only the published version is sent; editing the draft does not change your emails until
you publish again. Webhook events about the email carry the template's id as
data.template_id.
A send is refused, and nothing is sent, when:
| Problem | Error |
|---|---|
| No template of the project has that id or alias | 404 not_found Template not found |
| The template was never published | 400 validation_error template.id: the template `order-confirmation` is not published |
| A variable has no value and no fallback | 400 validation_error template.variables: missing template variables: PRICE (every one, at once) |
| A value is not a string or a number, or is too long or too large | 400 validation_error naming template.variables.<KEY> |
html or text is in the request | 400 validation_error html: `html` cannot be used with `template` |
| More than 50 values | 400 validation_error naming template.variables |
| One request (a batch counts as one) renders too much | 400 validation_error naming template |
Edit the draft
PATCH /templates/{id} changes the draft. Give
only the fields you change; null clears an optional one (an exx.sh addition: Resend
documents no way to clear a field), and variables replaces the whole list. name and
html cannot be null:
curl -X PATCH https://api.exx.sh/templates/order-confirmation \
-H "Authorization: Bearer $EXX_API_KEY" \
-H "Content-Type: application/json" \
-d '{"html": "<p>{{{PRODUCT}}} ships today.</p>", "subject": null, "variables": [{"key": "PRODUCT", "type": "string"}]}'The published version stays as it was until you publish again.
GET /templates/{id} shows the draft, with:
has_unpublished_versions:truewhen the content was edited since the last publish (and always before the first publish);current_version_id: the draft's version, which changes when an edit changes the content. Renaming the template or changing its alias does not.
Every create and edit is checked whole, and a refused one changes nothing. The answer names each problem with its field:
alias: may only contain ASCII letters, digits, `-`, `_` and `.`; html: line 1, column 4: `{{{` is not closed by `}}}`Check before you publish
POST /templates/{id}/check (an exx.sh addition)
looks over the draft before you publish it: its links, images, size, plain-text part,
subject, variables and what the content scan would say. Add ?version=published to check
the version your emails use now.
curl -X POST https://api.exx.sh/templates/order-confirmation/check \
-H "Authorization: Bearer $EXX_API_KEY"{
"object": "check",
"errors": 0,
"warnings": 2,
"results": [
{
"id": "link_unreachable",
"severity": "warning",
"message": "the link answers HTTP 404",
"detail": "https://acme.com/old-sale"
},
{
"id": "image_missing_alt",
"severity": "warning",
"message": "an image has no alt text: readers that block images or use a screen reader get nothing",
"detail": "https://acme.com/logo.png"
}
]
}With the TypeScript SDK: await exx.templates.check("order-confirmation"), or
exx.templates.check(id, { version: "published" }).
The draft is checked as an email would be sent: each variable takes its fallback_value, and
a variable without one stays as its tag ({{{ORDER_ID}}}). Results come in the order of the
table below, each with a stable id, a severity and, when it is about something in
particular, a detail (a URL, an image's src or a variable's name). An error should be
fixed before you send; a warning is worth a look. Each check reports at most
20 results, and one more counts the rest.
id | Severity | Reported when |
|---|---|---|
unknown_variable | error | A variable is used with no declared variable and no fallback |
fallback_missing | warning | {{{FIRST_NAME}}}, {{{LAST_NAME}}}, {{{contact.first_name}}} or {{{contact.last_name}}} has no fallback, so a contact without that name gets no email, and a template send to someone who is not a contact is refused: add one, like {{{contact.first_name|there}}} |
html_unsafe_to_scan | warning | A tag has more than 256 attributes: the HTML is not checked further, and emails get no generated plain-text part |
link_insecure | warning | A link or image uses http:// |
link_malformed | warning | A link is empty, goes to # only, is not a full URL, or uses a scheme mail clients do not open (javascript:) |
link_unreachable | warning | A link does not resolve, does not answer, or answers an HTTP error |
link_not_checked | warning | A link points to a private address or a port other than 80 and 443, or was not fetched within the limits below |
image_missing_alt | warning | An image has no alt attribute (alt="" marks a decorative image and is fine) |
html_clipped | warning | The HTML is larger than 102 KB: Gmail and other mailbox providers clip it |
text_missing | warning | The email would go without a plain-text part (text is "", or the HTML is too large or too deeply nested to make one from) |
subject_empty | warning | The template has no subject, so every email must give one |
subject_long | warning | The subject is longer than 60 characters |
preview_long | warning | The preview text (a hidden element at the top of the HTML) is longer than 140 characters |
content_held | warning | The content scan would hold an email with these links for review |
content_blocked | error | The content scan would refuse an email with these links |
Links are fetched from exx.sh's servers with HEAD, then GET when HEAD answers 400,
403, 405 or 501, only on public addresses and ports 80 and 443, with a
User-Agent that names exx.sh. Each URL (without its #fragment) is fetched once per check,
at most 20 of them, each request within
3 seconds and all within 10 seconds. An answer is
reused for 10 minutes, no answer or a server error for
30 seconds. A link built from a variable without a value is not
fetched. A project can run 1 check a second with bursts of
5, and an organization 2 a second with
bursts of 10; past that, or when exx.sh is running many checks at
once, the answer is 429 rate_limit_exceeded with Retry-After.
Checking needs the same access as editing: a full-access API key, or the developer role or
above in the dashboard.
In the dashboard
The Templates page lists the project's templates. Open one to edit its draft next to a preview. Check runs the checks above on the draft, Publish makes it the version your emails use (both save your edits first), and Send a test sends the published version with values for its variables. A test to a test address costs nothing.
Ids and aliases
Every /templates/{id} endpoint takes the template's id or its alias. An alias is unique in
the project, up to 64 characters of ASCII letters, digits, -,
_ and . starting with a letter or digit, and is never a UUID. PATCH with "alias": null removes it, and deleting the
template frees it at once.
Duplicate, list and delete
POST /templates/{id}/duplicatemakes a new draft with the template's draft, named<name> (copy)and without an alias. The answer is the new template's id.GET /templateslists the templates newest first, 20 a page;limit(1 to 100),afterandbeforepage through them.DELETE /templates/{id}deletes a template for good.
An API key needs full access for every templates endpoint. In the dashboard every member can
read templates; changing them takes the developer role or above.
Forwarding received mail
Send mail received at your project's address or your domain on to another inbox, once its owner confirms, without spoofing the sender or opening a relay.
Contacts
Store a project's contacts, declare typed properties, set language and timezone, and distinguish deletion from erasure.