TypeScript · Nuxt
Send an email from a Nuxt server route (a Nitro event handler) with @messagebird/sdk. You'll need a Bird API key — create one in Developers → API keys as covered in Send your first email, then put it in .env as BIRD_API_KEY.
1. Install
Contoh kode
npm create nuxt@latest my-app && cd my-app
npm install @messagebird/sdk
# pnpm add @messagebird/sdk
# yarn add @messagebird/sdk
# bun add @messagebird/sdk2. Send
Create server/api/send.post.ts — everything under server/ runs only on the server:
Contoh kode
import { BirdClient } from "@messagebird/sdk";
const bird = new BirdClient({ apiKey: process.env.BIRD_API_KEY! });
export default defineEventHandler(async () => {
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 { id: msg.id, status: msg.status };
});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 region is inferred from your key's bk_us1_ / bk_eu1_ prefix, so there's no base URL to configure. The SDK auto-generates an Idempotency-Key per call, so retried sends are safe.
3. Try it
Run the dev server and POST to the route:
Contoh kode
npm run dev
curl -X POST http://localhost:3000/api/sendThe API responds with 202 — Bird has accepted the message and delivers it asynchronously:
Contoh kode
{
"id": "em_019c1930687b7bfa8a1b2c3d4e5f6789",
"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.