Skip to main content

MailFlat — Python SDK

Official Python client for MailFlat: disposable, automation-friendly email inboxes with one-line OTP retrieval. Spin up a real inbox, read the verification code your app just sent, and move on — no flaky polling, no shared mailbox state.

pip install mailflat

Quickstart

from mailflat import MailFlat

mf = MailFlat(api_key="mf_live_...")  # or set MAILFLAT_API_KEY

# 1 · spin up a disposable inbox
inbox = mf.create(label="signup-test")
print(inbox.address)            # → signup-test-8f3@x7k2m.mailflat.net

# 2 · your app/browser submits the form using inbox.address ...

# 3 · grab the OTP (polls until it arrives or times out)
otp = inbox.wait_for_otp(timeout=30)
print(otp)                      # → "123456"

# inbox auto-clears in 2h — no cleanup needed (or call inbox.delete())

For AI agents

Hand an agent one API key and it spins up real inboxes on demand:

mf = MailFlat()  # reads MAILFLAT_API_KEY

inbox = mf.create(label="deep-research")
browser.fill("#email", inbox.address)
browser.click("Sign up")

otp = inbox.wait_for_otp(timeout=30)
browser.fill("#code", otp)

API

MailFlat(api_key=None, *, base_url="https://mailflat.net", timeout=30.0, max_retries=2)

Client. api_key falls back to the MAILFLAT_API_KEY environment variable. Use base_url for self-hosted / BYOD deployments. Supports use as a context manager (with MailFlat() as mf:).

  • create(*, prefix=None, label=None, subdomain=None, domain=None, retention_hours=None) -> Inbox — open a new inbox. create_inbox(...) is an alias.
  • list() -> list[Inbox] — inboxes opened with this key.
  • inbox(address) -> Inbox — attach to an existing address without a network call.

Inbox

  • .address — the email address.
  • .messages() -> list[Message] — all messages, newest first.
  • .latest() -> Message | None — most recent message.
  • .wait_for_otp(*, timeout=30, poll_interval=1.0) -> str — poll until an OTP arrives; returns the code.
  • .wait_for_message(*, timeout=30, poll_interval=1.0) -> Message — poll until any message arrives.
  • .send(to, *, subject="", body="", html=None) -> dict — send a DKIM-signed email from this inbox.
  • .delete() -> dict — delete the inbox and all its messages.

Message

.otp, .subject, .sender, .text, .html, .to_address, .direction, .received_at, .raw.

Errors

All errors subclass MailFlatError: AuthenticationError (401), PermissionError (403), NotFoundError (404), RateLimitError (429), APIError (other), OTPTimeoutError (no OTP before timeout), EncryptedInboxError (the inbox is end-to-end encrypted, so the server cannot read its contents — use a non-encrypted inbox for agent automation).

License

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mailflat-0.3.1.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mailflat-0.3.1-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

File details

Details for the file mailflat-0.3.1.tar.gz.

File metadata

  • Download URL: mailflat-0.3.1.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for mailflat-0.3.1.tar.gz
Algorithm Hash digest
SHA256 49a3a57c688fc1b50bc39111d3af292953c5799195161f50e3062d4b42dabbfb
MD5 28bdc77649d38187d6dc8a4f5fe4e41a
BLAKE2b-256 0e0241677f92b2b77a2260b381b6f0b0b0157079f5c54d5bb7b7b9b8f923f5ae

See more details on using hashes here.

File details

Details for the file mailflat-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: mailflat-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 12.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for mailflat-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e15054144c6704e0390b2e25757702f260d34b033684c10bc541d3676aa5de88
MD5 45555448f273aca2e4be39b488776975
BLAKE2b-256 50739506f419286f449f9c861b4bb02e6b450acafa33a989bb44d5fcb8d14640

See more details on using hashes here.

Release history Release notifications | RSS feed

0.11.0

2 files

0.10.2

2 files

0.10.1

2 files

0.10.0

2 files

0.9.0

2 files

0.8.0

2 files

0.7.0

2 files

0.6.1

2 files

0.6.0

2 files

0.5.0

2 files

0.4.1

2 files

0.4.0

2 files

0.3.3

2 files

This release

0.3.1 This release

2 files

0.3.0

2 files

0.2.0

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page