Quickstarts
Send with Bun
Send email from Bun with the usend SDK or plain fetch.
You need a verified domain and an API key.
1. Install
bun add @usend/nodeBun loads .env files automatically:
USEND_API_KEY=us_1234567892. Send
import { Usend } from '@usend/node';
const usend = new Usend(Bun.env.USEND_API_KEY);
const { data, error } = await usend.emails.send({
from: 'Acme <[email protected]>',
to: ['[email protected]'],
subject: 'Hello from Bun',
html: '<p>It works!</p>',
});
console.log(error ?? data);bun run send.tsA small HTTP server
import { Usend } from '@usend/node';
const usend = new Usend(Bun.env.USEND_API_KEY);
Bun.serve({
port: 3000,
async fetch(req) {
if (req.method !== 'POST') return new Response('POST only', { status: 405 });
const { email } = await req.json();
const { data, error } = await usend.emails.send({
from: 'Acme <[email protected]>',
to: [email],
subject: 'Welcome',
text: 'Thanks for signing up.',
});
return Response.json(error ? { error } : { id: data.id }, { status: error ? 502 : 200 });
},
});Without the SDK
const res = await fetch('https://api.usend.et/emails', {
method: 'POST',
headers: { Authorization: `Bearer ${Bun.env.USEND_API_KEY}`, 'Content-Type': 'application/json' },
body: JSON.stringify({ from: 'Acme <[email protected]>', to: ['[email protected]'], subject: 'Hi', text: 'Hi' }),
});See Send emails for all fields.