The official Node.js SDK for FlySend — send transactional emails through the FlySend API.
- Node.js 18+
npm install flysendimport { FlySend } from 'flysend';
const flysend = new FlySend('your-api-key');
await flysend.emails.send({
from: 'hello@example.com',
to: 'user@example.com',
subject: 'Welcome!',
html: '<p>Hello world!</p>',
});const flysend = new FlySend({
apiKey: 'your-api-key',
baseUrl: 'https://api.flysend.co', // optional, for self-hosted instances
timeout: 30000, // optional, default 30s
});const response = await flysend.emails.send({
from: 'Company <hello@example.com>',
to: 'user@example.com',
subject: 'Welcome!',
html: '<p>Hello!</p>',
text: 'Hello!', // optional
cc: 'cc@example.com', // optional
bcc: 'bcc@example.com', // optional
reply_to: 'support@example.com', // optional
tags: [ // optional
{ name: 'campaign', value: 'welcome' },
],
attachments: [ // optional
{
filename: 'invoice.pdf',
content: base64EncodedContent,
mime_type: 'application/pdf',
},
],
});
console.log(response.data.id); // email IDSend up to 100 emails in a single request:
const response = await flysend.emails.batch([
{
from: 'hello@example.com',
to: 'user1@example.com',
subject: 'Hello User 1',
html: '<p>Hi!</p>',
},
{
from: 'hello@example.com',
to: 'user2@example.com',
subject: 'Hello User 2',
html: '<p>Hi!</p>',
},
]);
console.log(response.queued_count); // number of emails queued
console.log(response.error_count); // number of failuresimport { FlySend, FlySendError, ValidationError, QuotaExceededError } from 'flysend';
try {
await flysend.emails.send({ ... });
} catch (error) {
if (error instanceof QuotaExceededError) {
console.log('Quota exceeded:', error.quota.remaining);
} else if (error instanceof ValidationError) {
console.log('Validation errors:', error.errors);
} else if (error instanceof FlySendError) {
console.log('API error:', error.message, error.statusCode);
}
}MIT