Quickstarts
Send with Node.js
Send your first email from a Node.js script with the usend SDK.
You need a verified domain and an API key. The SDK needs Node.js 18 or newer and has no dependencies.
1. Install
npm install @usend/node2. Set your API key
export USEND_API_KEY="us_123456789"3. Send
Create send.mjs:
import { Usend } from '@usend/node';
const usend = new Usend(process.env.USEND_API_KEY);
const { data, error } = await usend.emails.send({
from: 'Acme <[email protected]>',
to: ['[email protected]'],
subject: 'Hello from usend',
html: '<p>It works!</p>',
});
if (error) {
console.error(error.statusCode, error.name, error.message);
process.exit(1);
}
console.log('queued', data.id);node send.mjsEvery SDK method resolves to { data, error }; exactly one of them is null, so you never need try/catch around API errors.
Plain HTTP instead
const res = await fetch('https://api.usend.et/emails', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.USEND_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({ from: 'Acme <[email protected]>', to: ['[email protected]'], subject: 'Hello', html: '<p>Hi</p>' }),
});
console.log(await res.json());Next steps
- Send emails for every field (cc, bcc, tags, headers, scheduling).
- Attachments and templates.
- Webhooks to follow delivery.