uSend Docs
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

Shell
bun add @usend/node

Bun loads .env files automatically:

.env
USEND_API_KEY=us_123456789

2. Send

send.ts
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);
Shell
bun run send.ts

A small HTTP server

server.ts
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

TypeScript
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.