# Envoyer des e-mails transactionnels avec Python

> Envoyez des e-mails transactionnels depuis Python avec le SDK Sendtern. Testez-les dans Email Playground, puis suivez la livraison avec l’identifiant du message.

## Conditions préalables

- Un Sendtern [clé API](https://sendtern.com/fr/docs/authentication) stocké sous la forme `SENDTERN_API_KEY`
- Python 3.9 ou version ultérieure

1. **Installer le SDK**: Exécutez cette commande dans votre projet.

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

2. **Envoyer un email**: Créez `send.py` et lancez-le avec `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. **Vérifiez la réponse**: Une requête réussie renvoie `200 OK` avec l'identifiant de l'email. Utilisez-le pour rechercher l'email plus tard.

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

## Tester sans envoyer

Enregistrez l’exemple sous `preview.py` et exécutez `python preview.py`. Ouvrez [Email Playground](https://sendtern.com/fr/dashboard/playground) pour examiner le message et ses en-têtes avant de configurer votre domaine d’envoi.

```
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"])
```

Pour un envoi réel, utilisez l’identifiant retourné pour [consulter les événements de livraison](https://sendtern.com/fr/docs/statuses). Les [offres d’e-mail transactionnel](https://sendtern.com/fr/pricing) indiquent les limites mensuelles.

> **tip:** Remplacez l'expéditeur de l'exemple par une adresse sur votre [domaine vérifié](https://sendtern.com/fr/docs/domains).
