Sendery
Sendery

Language SDKs

JavaScript and TypeScript

Send published Sendery templates from JavaScript and TypeScript.

Install
npm install @sendery/sdk
Source code

Requirements

Node.js 22.12+. The package uses ES module imports and includes TypeScript types.

Set up

Publish a welcome template with name and action_url variables, and create a project API key. Store it as SENDERY_API_KEY on your server. Use the SDK only on the server.

Shell
export SENDERY_API_KEY="your_project_api_key"

Send an email

The response contains the accepted email’s id and status.

JavaScript and TypeScript
import { Sendery } from '@sendery/sdk';

const apiKey = process.env.SENDERY_API_KEY;
if (!apiKey) throw new Error('Set SENDERY_API_KEY on your server.');

const sendery = new Sendery(apiKey);
const receipt = await sendery.send({
  to: '[email protected]',
  template: 'welcome',
  data: { name: 'Alex', action_url: 'https://example.com/start' },
});

console.log(receipt.id);

Retrieve an email

Use the returned ID to check delivery status.

JavaScript and TypeScript
const message = await sendery.get(receipt.id);
console.log(message.status);

Retry a send

Use a key such as welcome-123 for one email, and keep the payload unchanged on retries. retry(3) allows up to three additional attempts for temporary failures; send() alone makes one attempt.

JavaScript and TypeScript
const email = sendery.prepare({
  to: '[email protected]',
  template: 'welcome',
  data: { name: 'Alex', action_url: 'https://example.com/start' },
}, 'welcome-123');

const receipt = await email.retry(3).send();

Handle errors

Catch the SDK exception to inspect the status and code. Retry delays are in seconds. The example uses the prepared email from the retry example above.

JavaScript and TypeScript
import { SenderyError } from '@sendery/sdk';

try {
  const receipt = await email.retry(3).send();
  console.log(receipt.id);
} catch (error) {
  if (error instanceof SenderyError) {
    console.error(error.status, error.code, error.errors);
    // error.retryAfter is a delay in seconds, when provided.
  }
  throw error;
}