Official TypeScript / Node.js SDK for SMASHSEND
Easily integrate email marketing, transactional emails, automations, and contact management into your app.
- What is SMASHSEND?
- Installation
- Setup
- Usage
- Advanced Configuration
- Using with Next.js
- Error Handling
- TypeScript Support
- Automated Publishing Workflow
- Documentation
- Contributing
- License
SMASHSEND is a bold, modern email platform built for business owners, creators, and startups — not just marketers.
- ⚡️ Drag-and-drop email builder
- 🪄 AI-powered personalization (“Magic Boxes”)
- 🤖 Automations & event triggers
- 🚀 High-deliverability transactional email API
- 🗂️ Lightweight CRM & contact management
- 📈 Deep analytics & link tracking
npm install @smashsend/node # or yarn add @smashsend/node / pnpm add @smashsend/node
Get an API key from the SMASHSEND Dashboard:
import { SmashSend } from '@smashsend/node';
const smashsend = new SmashSend(process.env.SMASHSEND_API_KEY!);
import {
SmashSend,
SmashsendContactStatus,
SmashsendCountryCode,
} from '@smashsend/node';
const smashsend = new SmashSend(process.env.SMASHSEND_API_KEY!);
const { contact } = await smashsend.contacts.create({
email: 'newcontact@example.com', // required
firstName: 'John',
lastName: 'Doe',
phone: '+1234567890',
status: SmashsendContactStatus.SUBSCRIBED, // defaults to SUBSCRIBED
countryCode: SmashsendCountryCode.US,
customProperties: {}, // define in dashboard first
});
console.log(contact.id); // contact UUID
console.log(contact.properties.email); // newcontact@example.com
const response = await smashsend.emails.send({
from: 'you@example.com',
to: 'recipient@example.com',
subject: 'Hello from SMASHSEND',
text: 'This is a test email from the SMASHSEND Node.js SDK.',
html: '<p>This is a test email from the <strong>SMASHSEND Node.js SDK</strong>...</p>',
});
// Add multiple headers
smashsend.setHeaders({
'X-Custom-Header': 'value',
'X-Tracking-ID': 'campaign-123',
});
// Or add an individual header
smashsend.setHeader('X-Source', 'website');
smashsend.setDebugMode(true); // logs all requests & responses
const smashsend = new SmashSend(process.env.SMASHSEND_API_KEY!, {
maxRetries: 5, // default 3
timeout: 60000,
});
This SDK works in Next.js 14+: server components, edge functions, API routes, and server actions.
// lib/smashsend.ts
import { SmashSend } from '@smashsend/node';
let client: SmashSend;
export function getSmashSendClient(apiKey?: string) {
if (!client) {
client = new SmashSend(apiKey ?? process.env.SMASHSEND_API_KEY!);
}
return client;
}
// app/contacts/page.tsx
import { getSmashSendClient } from '@/lib/smashsend';
export default async function ContactsPage() {
const smashsend = getSmashSendClient();
const { contacts } = await smashsend.contacts.list();
return (
<ul>
{contacts.map(c => (
<li key={c.id}>
{c.properties.firstName} ({c.properties.email})
</li>
))}
</ul>
);
}
// app/api/contact/route.ts
import {
getSmashSendClient,
SmashsendContactStatus,
SmashsendCountryCode,
} from '@/lib/smashsend';
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const data = await req.json();
try {
const smashsend = getSmashSendClient();
const { contact } = await smashsend.contacts.create({
email: data.email,
status: SmashsendContactStatus.SUBSCRIBED,
countryCode: SmashsendCountryCode.US,
customProperties: data.customFields,
});
return NextResponse.json({ success: true, contact });
} catch (err: any) {
return NextResponse.json({ success: false, error: err.message }, { status: 400 });
}
}
import { SmashSend, SmashSendError } from '@smashsend/node';
try {
await smashsend.emails.send({ /* … */ });
} catch (err) {
if (err instanceof SmashSendError) {
console.error(err.statusCode, err.requestId, err.message);
} else {
console.error('Unexpected error', err);
}
}
- Built in TypeScript
- Complete type definitions for all resources & enums
- Works with
strictNullChecks
,moduleResolution=node
, etc.
GitHub Actions publishes to npm automatically.
Branch | Release type |
---|---|
beta |
Prereleases x.y.z-beta.n |
main |
Stable releases x.y.z |
Version bumps & Git tags (v1.2.3
/ v1.2.3-beta.4
) are handled for you.
NPM_TOKEN → Settings ▸ Secrets ▸ Actions
Full API reference → https://smashsend.com/docs/api
We ❤️ PRs!
- Fork →
git checkout -b feat/awesome
- Add tests & docs
- PR against
beta
ormain