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
- Connect AWS SES under Project → Email provider
- Publish your template to SES
- 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',
});
| Field | Required | Description |
|---|---|---|
template | Yes | Template UUID (must be published to SES) |
to | Yes | Recipient email or array |
data | No | Runtime template variables |
from | No | Override project default from address |
replyTo | No | Reply-to address or array |
cc / bcc | No | Additional 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);
}
}
Related
- AWS SES guide — connect, verify, and publish templates
- Automations — lifecycle email from MongoDB or Excel
- Campaigns — one-off broadcasts from the dashboard