# Send email from Python

`pip install mailset`, then `mailset.send()` with a dict, and the receipt comes back as one. There’s a client for blocking code and one for asyncio, and mypy --strict checks every type.

## Install the Python SDK

pip, uv or Poetry. It runs on Python 3.9 and later, and brings httpx, cryptography and typing_extensions with it.

pip:

```bash
pip install mailset
```

uv:

```bash
uv add mailset
```

poetry:

```bash
poetry add mailset
```

## Send your first email from Python

`Mailset()` reads `MAILSET_KEY` from the environment. The message is a plain dict, so `"from"` is an ordinary key where a keyword argument couldn’t be. `"deliver_by": "10m"` refuses a code that can’t go out in ten minutes, and the receipt is a dict too: `sent["id"]`, `sent["status"]`. A refusal raises `MailsetError`.

```python
from mailset import Mailset

# Reads MAILSET_KEY from the environment.
mailset = Mailset()

sent = mailset.send(
    {
        "from": "Acme <hello@example.com>",
        "to": "ana@example.org",
        "subject": "Your Acme code",
        "text": "Your code is 123456.",
        "html": "<p>Your code is <b>123456</b>.</p>",
        "deliver_by": "10m",
    }
)

print(sent["id"], sent["status"])
```

## Delivery events in your framework

Every outcome of every message, posted to your server and signed. The guides for FastAPI, Django and Flask each have the endpoint, which hands the raw body to `webhooks.verify` before any JSON parsing.

- [Send email from FastAPI](https://mailset.app/send-email/fastapi)
- [Send email from Django](https://mailset.app/send-email/django)
- [Send email from Flask](https://mailset.app/send-email/flask)

## Send from your own domain

Your product sends as your own domain either way. What changes is where your team’s mail lives.

- **Sending only.** Your team’s mail stays at Google, Microsoft or wherever it is now. Mailset asks for DKIM, a bounce host and DMARC, and leaves your MX alone. [Send from a domain whose mail stays elsewhere](https://mailset.app/docs/recipes/sending-only)
- **Mailboxes too.** Your team’s mail moves to Mailset, with a real mailbox for every address on the domain and your product’s email on the same bill. [Set up a domain](https://mailset.app/guide/onboarding)

```bash
mailset domains add example.com --sending
mailset domains apply example.com --sending
mailset domains check example.com
mailset keys create --send --domain example.com --from hello@example.com --name "Acme API"
```

## What the Python SDK’s build checks

Each line comes from the SDK’s own build, which fails when one stops being true.

- **Python 3.9+**: The oldest its manifest allows (its manifest)
- **Typed throughout**: TypedDicts throughout, checked by mypy (a test)
- **Sync and async**: Mailset and AsyncMailset (a test)

## Where to go from here

- [The Python SDK](https://mailset.app/docs/sdk/python): Every task, from the client’s options to errors and retries.
- [Webhooks](https://mailset.app/docs/webhooks): The events Mailset posts about your product’s email, and how to check a request’s signature.
- [Give sign-in codes a deadline](https://mailset.app/docs/recipes/deadlines): Use deliverBy so a code that would arrive late is never sent.
- [Retry without sending twice](https://mailset.app/docs/recipes/retries): Make a send safe to repeat with an idempotency key or a Message-ID.
- [Handle bounces](https://mailset.app/docs/recipes/bounces): Tell a dead address from a full inbox, and keep your list clean.
- [Send many messages at once](https://mailset.app/docs/recipes/batches): Up to 100 messages a request, each with its own answer.

## Product email on every plan

Both include 10,000 emails a month, your product’s and your team’s together. Past that it’s $0.40 per 1,000 with pay as you go. Every plan and price: https://mailset.app/pricing

## Sending from Python, asked and answered

### Does it work with asyncio?

`AsyncMailset` has the same methods as coroutines: `await mailset.send(...)`. Close it with `await mailset.aclose()`, or open it in `async with`.

### Do I need smtplib or an app password?

No. Mailset takes mail over HTTPS, and the SDK signs each call with your key. There’s no SMTP host, port or password anywhere in your code.

### What does webhooks.verify take in Django or Flask?

The body exactly as it arrived: `request.body` in Django, `request.get_data()` in Flask. JSON that was parsed and written out again no longer matches the signature. The [Django](https://mailset.app/send-email/django) and [Flask](https://mailset.app/send-email/flask) guides have the whole view.

### Can one client serve the whole app?

Yes. Make one `Mailset()` when the app starts and import it where you send: it is safe to share between threads.

## Try it on your own domain

7 days free, with everything on. Make a key, run the example above and watch the receipt come back. Start at https://mailset.app/start

---

© 2026 Intenseloop, Inc. Mailset’s site, docs and guides are copyrighted. You may read them and use their code to build with Mailset. Don’t republish them or use them to build a copy of Mailset. Terms: https://mailset.app/terms#content