Quickstarts
Send with Hono
Send email from a Hono app with the usend SDK, on Node, Bun, Deno or Workers.
Hono runs on many runtimes; the usend SDK uses only fetch, so the same code works on all of them. You need a verified domain and an API key.
1. Install
npm install hono @usend/node2. Write the app
import { Hono } from 'hono';
import { Usend } from '@usend/node';
type Bindings = { USEND_API_KEY: string };
const app = new Hono<{ Bindings: Bindings }>();
app.post('/send', async (c) => {
const usend = new Usend(c.env.USEND_API_KEY);
const { email } = await c.req.json<{ email: string }>();
const { data, error } = await usend.emails.send({
from: 'Acme <[email protected]>',
to: [email],
subject: 'Welcome to Acme',
html: '<p>Thanks for signing up.</p>',
});
if (error) return c.json({ error }, 502);
return c.json({ id: data.id });
});
export default app;On Cloudflare Workers c.env holds your secrets. On Node, use process.env.USEND_API_KEY instead (with @hono/node-server's serve).
3. Run it
# Cloudflare Workers
npx wrangler secret put USEND_API_KEY
npx wrangler dev
# Then
curl -X POST localhost:8787/send -H 'Content-Type: application/json' -d '{"email":"[email protected]"}'Notes
- Create the client inside the handler when your runtime exposes secrets per request (Workers), or once at startup on Node.
- Check
error.statusCode:429means you hit a rate or quota limit, and theretry-afterheader tells you how long to wait.
More fields: Send emails.