# إرسال مع Next.js

> إرسال من معالج الطريق بحيث لا يصل المفتاح أبدا إلى المتصفح.

## الشروط المسبقة

- Sendtern [مفتاح البرنامج](https://sendtern.com/docs/authentication) مخزنة ك`SENDTERN_API_KEY`
- A Next.js 13.4+ app using the App Router

1. **أضف المفتاح**: أضف المفتاح إلى `.env.local` لا تضع علامة قبله `NEXT_PUBLIC_`، ذلك سيعرضه على المتصفح

```
SENDTERN_API_KEY=st_your_api_key
```

2. **Create a Route Handler**: Create `app/api/send/route.js`. It runs on the server only.

```
// app/api/send/route.js
export async function POST(request) {
  const { email } = await request.json();

  const res = await fetch("https://sendtern.com/emails", {
    method: "POST",
    headers: {
      Authorization: `Bearer ${process.env.SENDTERN_API_KEY}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      from: "Acme <hello@mail.example.com>",
      to: [email],
      subject: "Welcome to Acme",
      html: "<p>Thanks for signing up.</p>",
    }),
  });

  return Response.json(await res.json(), { status: res.status });
}
```

3. **تحقق من الإجابة**: طلب ناجح يعيد `200 OK` مع هوية البريد الإلكتروني. استخدمه للبحث عن البريد الإلكتروني في وقت لاحق.

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

> **tip:** استبدل المرسل المثالي بعنوان على [النطاق المتحقق منه](https://sendtern.com/docs/domains).
