sendcraft-sdk
v1.1.0
Published
Official SendCraft SDK for Node.js - Send transactional emails and campaigns via the SendCraft API
Maintainers
Readme
SendCraft Node.js SDK
Official Node.js SDK for SendCraft — send transactional emails and campaigns via the SendCraft API.
Installation
npm install sendcraft-sdkQuick Start
const SendCraft = require('sendcraft-sdk');
const client = new SendCraft({
apiKey: process.env.SENDCRAFT_API_KEY
});
const result = await client.sendEmail({
toEmail: '[email protected]',
subject: 'Welcome to SendCraft',
htmlContent: '<h1>Welcome!</h1><p>Thanks for signing up.</p>',
fromEmail: '[email protected]',
fromName: 'Your Company'
});
console.log('Email sent:', result);Features
- Send single emails
- Send bulk emails
- Schedule emails for later
- Create & manage campaigns
- Email templates
- Subscriber management
- Webhook configuration
- Analytics & reporting
- TypeScript support
- Full error handling
Usage Examples
Send Email
await client.sendEmail({
toEmail: '[email protected]',
subject: 'Hello!',
htmlContent: '<h1>Hello!</h1>',
fromEmail: '[email protected]'
});Send Bulk Emails
await client.sendBulkEmails({
emails: [
{ toEmail: '[email protected]', toName: 'John Doe' },
{ toEmail: '[email protected]', toName: 'Jane Smith' }
],
subject: 'Weekly Newsletter',
htmlContent: '<h1>This week...</h1>',
fromEmail: '[email protected]'
});Schedule Email
await client.scheduleEmail({
toEmail: '[email protected]',
subject: 'Reminder: Meeting Tomorrow',
htmlContent: '<p>Don\'t forget our meeting!</p>',
fromEmail: '[email protected]',
scheduledTime: new Date('2026-03-01T10:00:00Z')
});Create Campaign
const campaign = await client.createCampaign({
name: 'Product Launch',
subject: 'Introducing Our New Product',
fromEmail: '[email protected]',
htmlContent: '<h1>Big News!</h1>',
recipients: ['[email protected]', '[email protected]']
});
await client.sendCampaign(campaign.data.id);Manage Templates
const template = await client.createTemplate({
name: 'Welcome Email',
subject: 'Welcome to {{company}}',
htmlContent: '<h1>Hello {{name}}</h1>',
category: 'welcome',
variables: ['name', 'company']
});
const templates = await client.getTemplates();
await client.updateTemplate(template.data.id, { subject: 'Welcome {{name}}!' });
await client.deleteTemplate(template.data.id);Webhooks
await client.createWebhook({
name: 'Email Events',
url: 'https://yourdomain.com/webhooks/email',
events: ['email.sent', 'email.opened', 'email.clicked', 'email.bounced']
});Analytics
const stats = await client.getEmailStats();
const analytics = await client.getAnalytics('campaign-id');Error Handling
try {
await client.sendEmail({ /* ... */ });
} catch (error) {
if (error.message.includes('Unauthorized')) {
console.error('Invalid API key');
} else if (error.message.includes('Rate limited')) {
console.error('Too many requests, wait before retrying');
} else {
console.error('Error:', error.message);
}
}TypeScript Support
import SendCraft, { SendEmailParams, SendCraftResponse } from 'sendcraft-sdk';
const client = new SendCraft({ apiKey: process.env.SENDCRAFT_API_KEY! });
const params: SendEmailParams = {
toEmail: '[email protected]',
subject: 'Hello',
htmlContent: '<p>Test</p>'
};
const result: SendCraftResponse = await client.sendEmail(params);Environment Variables
SENDCRAFT_API_KEY=sk_live_your_key_hereconst SendCraft = require('sendcraft-sdk');
const client = new SendCraft({
apiKey: process.env.SENDCRAFT_API_KEY
});API Reference
| Method | Description |
|--------|-------------|
| sendEmail(params) | Send a single email |
| sendBulkEmails(params) | Send emails to multiple recipients |
| scheduleEmail(params) | Schedule email for future delivery |
| getEmailStats() | Get email statistics |
| createCampaign(params) | Create email campaign |
| getCampaigns(limit) | Get all campaigns |
| getCampaign(id) | Get campaign by ID |
| sendCampaign(id) | Send campaign |
| createTemplate(params) | Create email template |
| getTemplates() | Get all templates |
| getTemplate(id) | Get template by ID |
| updateTemplate(id, params) | Update template |
| deleteTemplate(id) | Delete template |
| addSubscriber(params) | Add subscriber to list |
| getSubscribers(listId, limit) | Get subscribers |
| removeSubscriber(id) | Remove subscriber |
| createWebhook(params) | Create webhook |
| getWebhooks() | Get all webhooks |
| deleteWebhook(id) | Delete webhook |
| getAnalytics(campaignId) | Get campaign analytics |
| getBillingInfo() | Get billing information |
| getAccount() | Get account details |
| updateAccount(params) | Update account |
| changePassword(old, new) | Change password |
Support
- Website: https://sendcraft.online
- Email: [email protected]
License
MIT
