# Next.js ile gönder

> Bir Yol İşleticisinden gönder, böylece anahtar hiçbir zaman tarayıcıya ulaşmaz.

## Önkoşullar

- `SENDTERN_API_KEY` olarak depolanan bir Sendtern [API anahtarı](https://sendtern.com/docs/authentication)
- A Next.js 13.4+ app using the App Router

1. **Anahtarı ekle**: Anahtarı `.env.local`'ye ekle. `NEXT_PUBLIC_` ile ön ekleme, bu onu tarayıcıya açık hale getirir.

```
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. **Cevapları kontrol et.**: Başarılı bir talep e-posta kimliğiyle `200 OK`'yi geri verir. Daha sonra e-postayı aramaya kullanın.

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

> **tip:** Örnek göndericiyi [verilen alan adı](https://sendtern.com/docs/domains) adresinizle değiştirin.
