# Node.js के साथ भेजें

> किसी भी Node.js 18+ परियोजना से ईमेल भेजें, जिसमें अंतर्निर्मित फ़ेटच का उपयोग किया जाता है।

## पूर्व आवश्यकताएँ

- एक Sendtern [API कुंजी](https://sendtern.com/docs/authentication) `SENDTERN_API_KEY` के रूप में भंडारित
- Node.js 18 or newer, which ships with `fetch`

1. **ईमेल भेजें**: Create `send.mjs`. No package is needed.

```
// send.mjs
const res = await fetch("https://sendtern.com/emails", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.SENDTERN_API_KEY}`,
    "Content-Type": "application/json",
    "Idempotency-Key": crypto.randomUUID(),
  },
  body: JSON.stringify({
    from: "Acme <hello@mail.example.com>",
    to: ["you@example.com"],
    subject: "Hello from Node.js",
    html: "<p>It works!</p>",
  }),
});

if (!res.ok) throw new Error((await res.json()).message);
console.log(await res.json());
```

2. **जवाब जाँचें**: एक सफल निवेदन ईमेल आईडी के साथ `200 OK` लौटाता है. ईमेल को बाद में देखने के लिए इसका उपयोग करें.

```
{
  "id": "47be30ca-24b7-48fb-b35d-ff287b89e66d"
}
```

```
node --env-file=.env send.mjs
```

> **tip:** उदाहरण प्रेषक को अपने [सत्यापित डोमेन](https://sendtern.com/docs/domains) पर एक पता के साथ बदलें.
