Sendery
Sendery

Framework Integrations

Next.js integration

Send transactional email from your Next.js server with the Sendery JavaScript SDK.

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

Requirements

Use the JavaScript SDK with the App Router on Node.js 22.12+. Create a project API key.

Set the API key

Add the key to .env.local for development or your hosting provider’s secret settings. Keep the variable private; do not prefix it with NEXT_PUBLIC_. Install the server-only marker package with npm install server-only for the helper below.

.env.local
SENDERY_API_KEY=your_project_api_key

Send from the server

Call sendEmail(input, emailKey) from your server code. Pass the recipient, published template key, and variables in input. Reuse emailKey and the same input when retrying.

TypeScript
// lib/send-email.ts
import 'server-only';
import { Sendery, type SendEmailInput } from '@sendery/sdk';

export async function sendEmail(input: SendEmailInput, emailKey: string) {
  const apiKey = process.env.SENDERY_API_KEY;
  if (!apiKey) throw new Error('Set SENDERY_API_KEY on your server.');

  const sendery = new Sendery(apiKey);
  return sendery.prepare(input, emailKey).retry().send();
}

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.

TypeScript
// lib/send-email.ts
import 'server-only';
import { Sendery, type SendEmailInput } from '@sendery/sdk';

export async function sendEmail(input: SendEmailInput, emailKey: string) {
  const apiKey = process.env.SENDERY_API_KEY;
  if (!apiKey) throw new Error('Set SENDERY_API_KEY on your server.');

  const sendery = new Sendery(apiKey);
  return sendery.prepare(input, emailKey).version(3).send();
}

Attachments

Use attachment() in your server-side code to include files in a send. 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();