Skip to content

smashsend/smashsend-node

Repository files navigation

SMASHSEND

Official TypeScript / Node.js SDK for SMASHSEND
Easily integrate email marketing, transactional emails, automations, and contact management into your app.

NPM Version License

SMASHSEND Node.js SDK

Table of Contents

  1. What is SMASHSEND?
  2. Installation
  3. Setup
  4. Usage
  5. Advanced Configuration
  6. Using with Next.js
  7. Error Handling
  8. TypeScript Support
  9. Automated Publishing Workflow
  10. Documentation
  11. Contributing
  12. License

What is SMASHSEND?

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

Explore more


Installation

npm install @smashsend/node       # or yarn add @smashsend/node / pnpm add @smashsend/node

Setup

Get an API key from the SMASHSEND Dashboard:

import { SmashSend } from '@smashsend/node';

const smashsend = new SmashSend(process.env.SMASHSEND_API_KEY!);

Usage

Create or update a contact

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

Send an email

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>',
});

Advanced Configuration

Custom Headers

// Add multiple headers
smashsend.setHeaders({
  'X-Custom-Header': 'value',
  'X-Tracking-ID':  'campaign-123',
});

// Or add an individual header
smashsend.setHeader('X-Source', 'website');

Debug Mode

smashsend.setDebugMode(true);   // logs all requests & responses

Retry Configuration

const smashsend = new SmashSend(process.env.SMASHSEND_API_KEY!, {
  maxRetries: 5,   // default 3
  timeout:    60000,
});

Using with Next.js

This SDK works in Next.js 14+: server components, edge functions, API routes, and server actions.

Helper

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

Server Component

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

API Route

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

Error Handling

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

TypeScript Support

  • Built in TypeScript
  • Complete type definitions for all resources & enums
  • Works with strictNullChecks, moduleResolution=node, etc.

Automated Publishing Workflow

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.

Required secret

NPM_TOKEN  →  Settings ▸ Secrets ▸ Actions

Documentation

Full API reference → https://smashsend.com/docs/api


Contributing

We ❤️ PRs!

  1. Forkgit checkout -b feat/awesome
  2. Add tests & docs
  3. PR against beta or main

License

MIT

About

SMASHSEND's Official Node.js SDK

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published