TypeScript SDK
Send email from Node.js, Bun, Deno and edge runtimes with @exx.sh/sdk. Install, configure, send, handle errors and retries, React Email, SMTP and webhooks.
@exx.sh/sdk is the official TypeScript client for the exx.sh API. It runs in Node.js 20+,
Bun, Deno and edge runtimes (it needs only fetch and WebCrypto), ships as ESM and CommonJS,
and has types for every module resolution (bundler, node16, nodenext). MIT licensed.
Install
npm install @exx.sh/sdkSend an email
import { Exx } from "@exx.sh/sdk";
const exx = new Exx(process.env.EXX_API_KEY);
const { data, error } = await exx.emails.send({
from: "Acme <hello@acme.com>",
to: ["delivered@example.com"],
subject: "Your sign-in link",
html: "<p>Click the link to sign in.</p>",
text: "Click the link to sign in.",
tags: [{ name: "category", value: "sign_in" }],
});
if (error) {
// error.name is the API's error name, e.g. "validation_error" or "rate_limit_exceeded".
console.error(`${error.name}: ${error.message}`);
process.exit(1);
}
console.log(data.id);emails.send and batch.send also take idempotencyKey and stream ("transactional"
or "distributional"). The sending guide explains every field.
Configure the client
new Exx(key?, options?) reads the key from EXX_API_KEY when you pass none.
| Option | Default | Meaning |
|---|---|---|
baseUrl | EXX_BASE_URL, then https://api.exx.sh | The API's address |
retries | 2 | Retries after the first attempt, below |
timeout | 30 s | The time limit of each attempt |
fetch | the runtime's fetch | Your own fetch implementation |
userAgent | the SDK's | The User-Agent header |
Every API method takes a last { signal } argument to cancel it, including the waits
between retries.
Handle errors
Methods return { data, error, headers } and never throw for an API error. error.name is
the API's error name, for a server error too, so you can branch on it as the
errors guide describes. An answer that did not come from the API (a
proxy's error page) is application_error with that answer's statusCode; no answer at all
is application_error with statusCode: null.
Retries
The client retries rate-limited requests (429), except a spent daily or monthly quota.
It retries server errors and lost answers only when sending again cannot act twice: any
request but a POST without an Idempotency-Key. While retries are on, each send gets a key
made for you, so a send is retried safely too. A send the server is still processing
(409 concurrent_idempotent_requests) is asked again until it has the answer. Between
attempts the client waits Retry-After, or an exponentially growing time.
Resources
| Resource | Methods |
|---|---|
emails | send, get, list, update, cancel, attempts and transcript (exx only) |
emails.attachments | list and get the attachments of a sent email |
emails.receiving | list and get received mail; emails.receiving.attachments: list and get its attachments (receiving email) |
emails.verify | an address's syntax, DNS and list findings (exx only, verify addresses) |
events | send (Resend's shape), create and listNames (exx only) (application events) |
workflows | create, get, list, update, remove, publish, pause, resume, duplicate, rotateSigningSecret and schema (exx only, workflows) |
workflows.versions | list and get a workflow's published versions |
workflows.runs | start (takes idempotencyKey), list, get, cancel and cancelAll |
batch | send |
domains | create, get, list, update, delete and verify domains; update takes dmarcReports, dmarcSummary, dmarcReports (exx only) |
apiKeys | create, list and revoke keys |
webhooks | create, get, list, update, delete webhooks and rotate their secret; create and update take domains (exx only) |
webhooks.deliveries | list, get and replay a webhook's deliveries (exx only) |
templates | create, get, list, update, publish, duplicate, remove; check (exx only) |
suppressions | list, add and remove suppressed addresses |
metrics | get (the series), providers, reputation (exx only) |
React Email
Pass a React Email component as react. The client renders it to
html with @react-email/render (install it with react and react-dom), as Resend's SDK
does. A given html wins over react.
import { Exx } from "@exx.sh/sdk";
import { WelcomeEmail } from "./emails/welcome";
const exx = new Exx(process.env.EXX_API_KEY);
await exx.emails.send({
from: "Acme <hello@acme.com>",
to: "delivered@example.com",
subject: "Welcome",
react: <WelcomeEmail name="Ada" />,
});SMTP
@exx.sh/sdk/smtp sends the same email shape over SMTP with nodemailer
(install it; Node.js only). React components work there too.
// SMTP from Node.js: `npm install @exx.sh/sdk nodemailer`. Same email shape as the API.
import { ExxSmtp } from "@exx.sh/sdk/smtp";
const smtp = new ExxSmtp(process.env.EXX_API_KEY); // smtp.exx.sh, port 465 (TLS)
const { data, error } = await smtp.send(
{
from: "Acme <hello@acme.com>",
to: ["delivered@example.com"],
subject: "Your sign-in link",
html: "<p>Click the link to sign in.</p>",
text: "Click the link to sign in.",
},
{ idempotencyKey: "sign-in/123" },
);
if (error) {
// "smtp_error" with error.smtpCode for a refusal, "validation_error" for what SMTP
// cannot carry (tags, scheduling, attachment paths).
console.error(`${error.name}: ${error.message}`);
process.exit(1);
}
console.log(data.id); // the same id the API and webhooks use
await smtp.close();new ExxSmtp(key?, { host, port, secure, tls, timeout }) connects to EXX_SMTP_HOST and
EXX_SMTP_PORT by default, then smtp.exx.sh and 465. Port 465 is TLS from the start and
any other port uses STARTTLS (secure: true forces TLS from the start); TLS is always
required. send takes { idempotencyKey, stream } but no signal, and timeout applies
to each connection phase. Tags, scheduling and attachment paths need the API.
Webhooks
Verify each webhook delivery against the raw body before you use it (webhooks guide):
import { Exx, WebhookVerificationError } from "@exx.sh/sdk";
const exx = new Exx(process.env.EXX_API_KEY);
// A fetch-style handler (Bun, Deno, Workers, Next.js route handlers).
export async function POST(request: Request): Promise<Response> {
try {
const event = await exx.webhooks.verify({
payload: await request.text(), // the raw body, before any JSON parsing
headers: request.headers,
webhookSecret: process.env.EXX_WEBHOOK_SECRET ?? "",
});
console.log(event);
return new Response(null, { status: 204 });
} catch (e) {
if (e instanceof WebhookVerificationError) return new Response(null, { status: 400 });
throw e;
}
}