TypeScript · Hono
Send an email from a Hono POST handler on Node.js with @messagebird/sdk. You need Node.js 20.3 or later and a Bird API key. Create a key in Developers > API keys (Send your first email walks through it), then export it as BIRD_API_KEY.
1. Install
Codevoorbeeld
npm create hono@latest my-app -- --template nodejs --pm npm --install
cd my-app
npm install @messagebird/sdk2. Send
Add the route in src/index.ts:
Codevoorbeeld
import { Hono } from "hono";
import { serve } from "@hono/node-server";
import { BirdClient } from "@messagebird/sdk";
const bird = new BirdClient({ apiKey: process.env.BIRD_API_KEY! });
const app = new Hono();
app.post("/send", async (c) => {
const msg = await bird.email.send({
from: "onboarding@messagebird.dev",
to: ["delivered@messagebird.dev"],
subject: "Hello from Bird",
html: "<p>My first Bird email.</p>",
});
console.log(msg.id, msg.status); // "em_…", "accepted"
return c.json({ id: msg.id, status: msg.status });
});
serve({
fetch: app.fetch,
port: 3000,
});onboarding@messagebird.dev is Bird's shared onboarding sender and delivered@messagebird.dev is a sandbox recipient that always delivers: no domain verification needed. The SDK infers the region from your key's bk_us1_ / bk_eu1_ prefix (no base URL to configure) and auto-generates an Idempotency-Key per call, so retried sends are safe.
3. Try it
Run the dev server and POST to the route:
Codevoorbeeld
npm run dev
curl -X POST http://localhost:3000/sendBird accepts the email with a 202 and delivers it asynchronously; your route returns the em_ ID and status:
Codevoorbeeld
{
"id": "em_01ky7ma8y2es1s2akzk53tmjn0",
"status": "accepted"
}Next steps
- TypeScript email SDK: the full email surface (send, get, list) and the error model.
- Send your first email: creating an API key and the full set of sandbox addresses.
- Sending domains: verify your own domain for production sending.
- Email API reference: the full request and response schema.
Gerelateerde bronnen
Ga verder met de documentatie, gidsen en voorbeelden voor dit onderwerp. De bronnen zijn in het Engels.
Bekijk de gidsGetting started with emailBegrijp het conceptShould I use a Bird SDK or call the API directly?Ontdek de mogelijkheidEmailVolg het leerpadBuild your first integration
Probeer de oefening en ontvang een implementatieoverzicht