postkit
SDKs

TypeScript SDK

Send transactional emails from Node.js, Next.js, Deno, and Bun with the Postkit TypeScript SDK

The Postkit TypeScript SDK is coming soon. In the meantime, use the REST API directly -- it takes under 5 minutes to get started.

Installation

npm install postkit
pnpm add postkit
yarn add postkit

Quick start

import { Postkit } from 'postkit';

const postkit = new Postkit('pk_live_abc123...');

const email = await postkit.emails.send({
  from: 'Acme <noreply@acme.eu>',
  to: ['user@example.com'],
  subject: 'Welcome to Acme',
  html: '<h1>Welcome!</h1><p>Thanks for signing up.</p>',
});

console.log(email.id); // em_...

Send with a template

const email = await postkit.emails.send({
  from: 'Acme <noreply@acme.eu>',
  to: ['user@example.com'],
  subject: 'Order Confirmation',
  template_id: 'tmpl_abc123',
  template_data: {
    order_id: '12345',
    total: '49.99',
  },
});

Send a batch

const result = await postkit.emails.sendBatch([
  {
    from: 'Acme <noreply@acme.eu>',
    to: ['alice@example.com'],
    subject: 'Welcome',
    html: '<p>Welcome, Alice!</p>',
  },
  {
    from: 'Acme <noreply@acme.eu>',
    to: ['bob@example.com'],
    subject: 'Welcome',
    html: '<p>Welcome, Bob!</p>',
  },
]);
// result.data contains per-email results

Domains

// List domains
const domains = await postkit.domains.list();

// Verify a domain
const verification = await postkit.domains.verify('dom_abc123');

Webhooks

// Create a webhook
const webhook = await postkit.webhooks.create({
  url: 'https://example.com/webhooks/postkit',
  events: ['email.delivered', 'email.bounced'],
});

// Verify a webhook signature
import { verifyWebhookSignature } from 'postkit';

const isValid = verifyWebhookSignature(
  payload,
  headers['webhook-signature'],
  webhook.signing_secret,
);

Available resources

ResourceMethods
postkit.emailssend(), sendBatch(), get(), list(), cancel()
postkit.domainscreate(), list(), get(), verify(), delete()
postkit.templatescreate(), list(), get(), update(), delete(), publish(), preview()
postkit.webhookscreate(), list(), get(), update(), delete(), rotateSecret()
postkit.suppressionscreate(), list(), get(), delete()
postkit.inboundlist(), get()
postkit.apiKeyscreate(), list(), get(), update(), delete()

For full endpoint documentation, see the API Reference.