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 postkitpnpm add postkityarn add postkitQuick 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 resultsDomains
// 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
| Resource | Methods |
|---|---|
postkit.emails | send(), sendBatch(), get(), list(), cancel() |
postkit.domains | create(), list(), get(), verify(), delete() |
postkit.templates | create(), list(), get(), update(), delete(), publish(), preview() |
postkit.webhooks | create(), list(), get(), update(), delete(), rotateSecret() |
postkit.suppressions | create(), list(), get(), delete() |
postkit.inbound | list(), get() |
postkit.apiKeys | create(), list(), get(), update(), delete() |
For full endpoint documentation, see the API Reference.