Send email with Hono
A server-side call to the SendSend API from your Hono app.
- Create a test API key in the dashboard first: it never delivers real email. Switch to a live key once your domain is verified.
- On Cloudflare Workers, run: wrangler secret put SENDSEND_API_KEY. On Node or Bun, use an environment variable.
- Add this to
src/index.ts:
import { Hono } from 'hono';
const app = new Hono<{ Bindings: { SENDSEND_API_KEY: string } }>();
app.post('/send', async (c) => {
const { to } = await c.req.json();
const res = await fetch('https://api.sendsend.email/v1/emails', {
method: 'POST',
headers: { Authorization: `Bearer ${c.env.SENDSEND_API_KEY}`, 'Content-Type': 'application/json', 'Idempotency-Key': crypto.randomUUID() },
body: JSON.stringify({ from: 'Acme <hello@mail.acme.com>', to: [to], subject: 'Hello from Hono', html: '<p>It works!</p>' }),
});
return c.json(await res.json(), res.status as 200);
});
export default app;Good to know
- A
202response means the message was queued, not delivered. See message states and webhooks. - Always send an Idempotency-Key, so a retry cannot send twice.
- Check the response status. Errors have one shape: see Errors.
- More options: attachments, scheduling, headers, templates and React Email.