Node.js SDK

The official Node.js client (@emailspace/sdk) sends templated email through EmailSpace's public API. EmailSpace delivers via your project's connected AWS SES account — no AWS credentials in your app.

Sends are recorded automatically in Analytics → Messages, with delivery status updated from SES webhooks.

Requires Node.js 18+.

Prerequisites

  1. Connect AWS SES under Project → Email provider
  2. Publish your template to SES
  3. Create an API key under Project → API credentials

Install

npm install @emailspace/sdk

From this monorepo:

npm install ./sdk

Configuration

import { EmailSpace } from '@emailspace/sdk';

const emailSpace = new EmailSpace({
  apiKey: process.env.EMAILSPACE_API_KEY!,
  projectId: process.env.EMAILSPACE_PROJECT_ID!,
  baseUrl: process.env.EMAILSPACE_BASE_URL, // optional, default http://localhost:3001
});

Get API key and project ID from the dashboard (Project → API credentials). Copy the template UUID from your template list.

Send email

const result = await emailSpace.send({
  template: '550e8400-e29b-41d4-a716-446655440000',
  to: 'john@example.com',
  data: {
    firstName: 'John',
    offerCode: 'SPRING20',
  },
});

console.log(result.messageId, result.acceptedRecipients);

Multiple recipients and options

await emailSpace.send({
  template: '550e8400-e29b-41d4-a716-446655440000',
  to: ['a@example.com', 'b@example.com'],
  cc: ['manager@example.com'],
  data: { firstName: 'Alex' },
  from: 'hello@yourdomain.com',
  replyTo: 'support@yourdomain.com',
});
FieldRequiredDescription
templateYesTemplate UUID (must be published to SES)
toYesRecipient email or array
dataNoRuntime template variables
fromNoOverride project default from address
replyToNoReply-to address or array
cc / bccNoAdditional recipients

Errors

import { EmailSpaceError, EmailSpaceNetworkError } from '@emailspace/sdk';

try {
  await emailSpace.send({ ... });
} catch (error) {
  if (error instanceof EmailSpaceError) {
    console.error(error.statusCode, error.code, error.message);
  } else if (error instanceof EmailSpaceNetworkError) {
    console.error('Network error', error.message);
  }
}