# Kirim dengan Python

> Kirim email dari Python dengan pustaka permintaan.

## Prerequisites

- Sebuah Sendtern [kunci API](https://sendtern.com/docs/authentication) disimpan sebagai `SENDTERN_API_KEY`
- Python 3.8 or newer

1. **Pasang permintaan**: Klien HTTP apapun bekerja. Panduan ini menggunakan `requests`.

```
pip install requests
```

2. **Kirim email**: Create `send.py`.

```
# send.py
import os
import uuid
import requests

res = requests.post(
    "https://sendtern.com/emails",
    headers={
        "Authorization": f"Bearer {os.environ['SENDTERN_API_KEY']}",
        "Idempotency-Key": str(uuid.uuid4()),
    },
    json={
        "from": "Acme <hello@mail.example.com>",
        "to": ["you@example.com"],
        "subject": "Hello from Python",
        "html": "<p>It works!</p>",
    },
    timeout=10,
)

res.raise_for_status()
print(res.json())
```

3. **Periksa responnya**: Sebuah permintaan yang berhasil mengembalikan `200 OK` dengan id surat elektronik. Gunakan untuk mencari surat elektronik nanti.

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

> **tip:** Ganti contoh pengirim dengan alamat di komputer Anda [domain yang diverifikasi](https://sendtern.com/docs/domains).
