Sendery
Sendery

Language SDKs

JavaScript and TypeScript

Send published Sendery templates from JavaScript and TypeScript.

Install
npm install @sendery/[email protected]
Source code

Requirements

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

Set up

Choose a published template and create a project API key. Store the key as SENDERY_API_KEY on your server.

Shell
export SENDERY_API_KEY="your_project_api_key"

Send an email

Replace your-template with your published template’s key and data with its variables.

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: 'your-template',
  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 retry(3) for up to three extra attempts after temporary failures. Keep the same idempotency key and email data on every attempt.

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

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;
}

Send a specific version

Choose a published template version to keep sending it after newer versions are published. By default, Sendery uses the latest version.

JavaScript
const receipt = await sendery.prepare({
    to: '[email protected]',
    template: 'your-template',
    data: { name: 'Alex', action_url: 'https://example.com/start' },
}).version(3).send();

Attachments

Use attachment() to create an attachment from file bytes. The helper handles base64 encoding.

Send up to 10 files totaling 5 MB. See the attachment reference for supported formats and limits.

Example
import { Sendery, attachment } from '@sendery/sdk';
import { readFile } from 'node:fs/promises';

const sendery = new Sendery(process.env.SENDERY_API_KEY);
const file = await readFile('/path/document.pdf');

await sendery.prepare({
    to: '[email protected]',
    template: 'your-template',
    data: { name: 'Alex', action_url: 'https://example.com/start' },
    attachments: [attachment('document.pdf', file, 'application/pdf')],
}, 'your-idempotency-key').retry().send();