Sign inGet started

TypeScript / Node.js

Send an email from a plain Node.js script with @messagebird/sdk. You need a Bird API key: create one in Developers > API keys (Send your first email walks through it), then export it as BIRD_API_KEY.

1. Install

कोड उदाहरण
npm init -y
npm install @messagebird/sdk tsx
The SDK requires Node.js 20.3+ and is ESM-only.

2. Send

Create send.ts:
कोड उदाहरण
import { BirdClient } from "@messagebird/sdk";

const bird = new BirdClient({ apiKey: process.env.BIRD_API_KEY! });

const msg = await bird.email.send({
  from: { email: "onboarding@messagebird.dev", name: "Bird" },
  to: ["delivered@messagebird.dev"],
  subject: "Hello from Bird",
  html: "<p>My first Bird email.</p>",
});

console.log(msg.id, 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 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. Run it

कोड उदाहरण
npx tsx send.ts
The script prints the message ID and status:
कोड उदाहरण
em_01ky7ma8y2es1s2akzk53tmjn0 accepted
accepted is the API's 202: Bird has the message and delivers it asynchronously. Fetch it by its em_ ID with bird.email.get(msg.id) and watch the status move to delivered.

Next steps

संबंधित संसाधन

इस विषय के लिए डॉक्यूमेंटेशन, गाइड और उदाहरणों के साथ आगे बढ़ें। संसाधन अंग्रेज़ी में हैं।

अभ्यास करें और इम्प्लीमेंटेशन ब्रीफ़ पाएँ