Official Python SDK for MailCue — open-source email testing and production server.
Project description
MailCue Python SDK
Official Python client for MailCue — the open-source email testing and production server (Postfix + Dovecot + FastAPI + React) packaged as one Docker container.
The SDK is the same in dev and prod: point it at http://localhost:8088 while
you build, then swap base_url to your production MailCue deployment when you
ship.
Install
pip install mailcue
Requires Python 3.9+.
Quick start: send an email
from mailcue import Mailcue
client = Mailcue(api_key="mc_xxx") # base_url defaults to http://localhost:8088
result = client.emails.send(
from_="hello@example.com",
to=["user@example.com"],
subject="Welcome",
html="<h1>Hi there</h1>",
)
print(result.message_id)
Need async? Use AsyncMailcue — same surface, all methods become coroutines:
import asyncio
from mailcue import AsyncMailcue
async def main() -> None:
async with AsyncMailcue(api_key="mc_xxx") as client:
await client.emails.send(
from_="hello@example.com",
to=["user@example.com"],
subject="Welcome",
html="<h1>Hi there</h1>",
)
asyncio.run(main())
Listing an inbox
inbox = client.emails.list(mailbox="user@example.com", page_size=20)
for email in inbox.emails:
print(email.uid, email.subject, email.from_address)
detail = client.emails.get(inbox.emails[0].uid, mailbox="user@example.com")
print(detail.text_body)
Attachments
attachments accepts raw bytes, str, or a pathlib.Path. The SDK
base64-encodes the content for you.
from pathlib import Path
client.emails.send(
from_="hello@example.com",
to=["user@example.com"],
subject="Invoice",
html="<p>See attached.</p>",
attachments=[
{
"filename": "invoice.pdf",
"content_type": "application/pdf",
"content": Path("./invoice.pdf"),
}
],
)
Real-time events (SSE)
for event in client.events.stream():
print(event.event_type, event.data)
The async version:
async with AsyncMailcue(api_key="mc_xxx") as client:
async for event in client.events.stream():
print(event.event_type, event.data)
The SSE client auto-reconnects with exponential backoff if the connection drops.
Error handling
from mailcue import (
Mailcue,
AuthenticationError,
NotFoundError,
RateLimitError,
ValidationError,
)
client = Mailcue(api_key="mc_xxx")
try:
client.emails.get("not-a-real-uid", mailbox="user@example.com")
except NotFoundError as exc:
print("missing:", exc)
except RateLimitError as exc:
print(f"slow down; retry after {exc.retry_after}s")
except AuthenticationError:
print("bad API key")
except ValidationError as exc:
print("server rejected the request:", exc.detail)
Configuration
client = Mailcue(
api_key="mc_xxx", # or bearer_token="eyJ..."
base_url="https://mail.example.com", # default: http://localhost:8088
timeout=30.0, # seconds
max_retries=3, # 502/503/504 + network errors
verify=True, # set False for self-signed dev TLS
)
You can also inject your own httpx.Client / httpx.AsyncClient via
http_client= for advanced cases (custom transports, proxies, mTLS).
Resources
| Resource | Methods |
|---|---|
client.emails |
send, list, get, get_raw, get_attachment, delete, inject, bulk_inject |
client.mailboxes |
list, create, delete, stats, purge, list_emails |
client.domains |
list, create, get, verify_dns, delete |
client.aliases |
list, create, get, update, delete |
client.gpg |
list, generate, get, export_public, import_key, publish, delete |
client.api_keys |
list, create, delete |
client.system |
health, get_certificate, download_certificate, settings, tls_status |
client.events |
stream() (SSE iterator) |
License
MIT — see LICENSE.
Project home: https://github.com/Olib-AI/mailcue
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mailcue-0.1.0.tar.gz.
File metadata
- Download URL: mailcue-0.1.0.tar.gz
- Upload date:
- Size: 17.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
523cb255bba74fd230d587b3ec9c69ac53b290e5bddc43b686f1637dce84faf5
|
|
| MD5 |
6c886af3552baf48a6cebdfbe045ee68
|
|
| BLAKE2b-256 |
c1181a14acd54db20d8bcc4ac612aef769264e940284ab09597e3812ea4b4dfc
|
Provenance
The following attestation bundles were made for mailcue-0.1.0.tar.gz:
Publisher:
sdk-publish.yml on Olib-AI/mailcue
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mailcue-0.1.0.tar.gz -
Subject digest:
523cb255bba74fd230d587b3ec9c69ac53b290e5bddc43b686f1637dce84faf5 - Sigstore transparency entry: 1429484437
- Sigstore integration time:
-
Permalink:
Olib-AI/mailcue@7a5dea78b5bc80a6f90914dfbe5a8a309daa1ccf -
Branch / Tag:
refs/tags/python-sdk-v0.1.0 - Owner: https://github.com/Olib-AI
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
sdk-publish.yml@7a5dea78b5bc80a6f90914dfbe5a8a309daa1ccf -
Trigger Event:
push
-
Statement type:
File details
Details for the file mailcue-0.1.0-py3-none-any.whl.
File metadata
- Download URL: mailcue-0.1.0-py3-none-any.whl
- Upload date:
- Size: 24.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
94d791d3897457a5a001943c6389ea7b52ee80a1d1871eefc353be26431aa066
|
|
| MD5 |
2c9ce3f0f2f1ccecd5bd37c04de87c41
|
|
| BLAKE2b-256 |
1890ab789986220894b40e42b482c88ac967ebc40eed3862d48c87848cfdb345
|
Provenance
The following attestation bundles were made for mailcue-0.1.0-py3-none-any.whl:
Publisher:
sdk-publish.yml on Olib-AI/mailcue
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mailcue-0.1.0-py3-none-any.whl -
Subject digest:
94d791d3897457a5a001943c6389ea7b52ee80a1d1871eefc353be26431aa066 - Sigstore transparency entry: 1429484439
- Sigstore integration time:
-
Permalink:
Olib-AI/mailcue@7a5dea78b5bc80a6f90914dfbe5a8a309daa1ccf -
Branch / Tag:
refs/tags/python-sdk-v0.1.0 - Owner: https://github.com/Olib-AI
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
sdk-publish.yml@7a5dea78b5bc80a6f90914dfbe5a8a309daa1ccf -
Trigger Event:
push
-
Statement type: