# Inviare email transazionali con Python

> Invia email transazionali da Python con l’SDK Sendtern. Fai una prova in Email Playground e segui la consegna effettiva con l’ID dell’email.

## Prerequisiti

- Un Sendtern [chiave API](https://sendtern.com/it/docs/authentication) memorizzato come `SENDTERN_API_KEY`
- Python 3.9 o versione successiva

1. **Installa l’SDK**: Esegui questo comando nel tuo progetto.

```
python -m pip install https://github.com/Sendtern/sendtern-sdks/releases/download/v0.3.0/sendtern-0.3.0-py3-none-any.whl
```

2. **Invia un messaggio**: Crea `send.py` ed esegui `python send.py`.

```
import os
from sendtern import Sendtern

client = Sendtern(os.environ["SENDTERN_API_KEY"])
result = client.emails.send({
  "from": "Acme <hello@mail.example.com>",
  "to": "you@example.com",
  "subject": "Welcome to Acme",
  "text": "Thanks for signing up."
})
print(result["id"])
```

3. **Controlla la risposta**: Una richiesta riuscita restituisce `200 OK` con l'ID email. Usalo per cercare l'email in seguito.

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

## Prova senza inviare

Salva l’esempio come `preview.py` ed esegui `python preview.py`. Apri [Email Playground](https://sendtern.com/it/dashboard/playground) per controllare il messaggio e le intestazioni prima di configurare il dominio di invio.

```
import os
from sendtern import Sendtern

client = Sendtern(os.environ["SENDTERN_API_KEY"])
result = client.emails.capture({
  "from": "sandbox@sendtern.test",
  "to": "recipient@example.com",
  "subject": "Welcome email preview",
  "html": "<p>Thanks for signing up.</p>"
})
print(result["id"])
```

Per un invio reale, usa l’ID restituito per [controllare gli eventi di consegna](https://sendtern.com/it/docs/statuses). Consulta i [piani per email transazionali](https://sendtern.com/it/pricing) per i limiti mensili.

> **tip:** Sostituisci il mittente di esempio con un indirizzo sul tuo [dominio verificato](https://sendtern.com/it/docs/domains).
