Node SDK

@torvath/mail: the email API, typed, for Node.

Send transactional email, check what happened to it and take its events. Works on Node 18+, Cloudflare Workers, Bun and Deno, with no dependencies.

npm install @torvath/mail

Small, typed and safe to retry.

Typed from the API

Types are generated from the same OpenAPI description the API uses.

Runs anywhere

Node 18+, Cloudflare Workers, Bun and Deno.

No dependencies

Nothing else to install or keep up to date.

Safe retries

An idempotency key on every send. Pass your own to tie it to your records.

Event listener

Listen for events and acknowledge each one when your handler finishes.

Clear errors

Errors carry a code and the fields that caused them.

Send

Send an email.

Make a key under Admin → API in Torvath, then send from any address on a verified domain.

  • Attachments as base64
  • Tags and metadata for your own records
  • emails.get(id) shows each recipient's status
send.ts
import { Torvath } from "@torvath/mail";

const torvath = new Torvath({ apiKey: process.env.TORVATH_API_KEY! });

const { id } = await torvath.emails.send({
  from: { email: "billing@yourcompany.in", name: "Your Company" },
  to: "customer@example.com",
  subject: "Invoice 1042",
  html: "<p>Your invoice is attached.</p>",
  tags: ["invoice"],
});

Templates

Send a template by name.

On Business, make templates with {{name}} where a detail goes. A missing variable is refused, so a half-filled email never goes out.

  • Values are made safe in the HTML
  • missing_variables lists what is missing
  • Templates are managed under Admin → API
template.ts
await torvath.emails.send({
  from: "billing@acme.in",
  to: "a@b.in",
  template: "invoice-ready",
  variables: { name: "Asha", amount: "₹500" },
});

Events

Listen for what happens.

An event is acknowledged only when your handler finishes without throwing. If it throws, the event comes back after 60 seconds.

  • Choose the event types you want
  • Make handlers safe to run twice
  • Call stop() to end the listener
events.ts
const listener = torvath.events.listen(
  { types: ["email.bounced", "email.complained"] },
  async (event) => {
    await markAddressBad(event.recipient, event.reason);
  },
);

// later
await listener.stop();

Where it runs

ItemSupported
Node.js18 and later
Cloudflare WorkersYes
BunYes
DenoYes
DependenciesNone

Questions

Not yet. The API is plain JSON over HTTPS, so any language can call it directly.

Make a test key (it starts tv_test_). Everything is checked, nothing is sent, and events arrive straight away.

Each send carries an idempotency key, so a retry never sends twice. Pass your own key to tie it to your records.

npm install @torvath/mail

Then get an API key and send your first email.