# Send transactional email with Python

> Send transactional email from Python with the Sendtern SDK. Test in Email Playground and track live delivery by email ID.

## Prerequisites

- A Sendtern [API key](https://sendtern.com/docs/authentication) stored as `SENDTERN_API_KEY`
- Python 3.9 or newer

1. **Install the SDK**: Run this command in your project.

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

2. **Send an email**: Create `send.py` and run it with `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. **Check the response**: A successful request returns `200 OK` with the email id. Use it to look the email up later.

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

## Test without sending

Save this as `preview.py` and run `python preview.py`. Open [Email Playground](https://sendtern.com/dashboard/playground) to inspect the message and its headers before setting up a sending domain.

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

For live email, use the returned ID to [check delivery events](https://sendtern.com/docs/statuses). See the [transactional email plans](https://sendtern.com/pricing) for monthly sending limits.

> **tip:** Replace the example sender with an address on your [verified domain](https://sendtern.com/docs/domains).
