Skip to main content

mailtm

A Python client library for the mail.tm temporary email API. No API key or signup required — create a disposable inbox and receive emails over REST.

Installation

Requires Python 3.8+ and requests (installed automatically).

From GitHub:

pip install git+https://github.com/irawrre/mailtm.git

From PyPI:

pip install mailtm-unofficial

From source / for development:

git clone https://github.com/irawrre/mailtm.git
cd mailtm
pip install .

Quick start

from mailtm import MailTM

with MailTM() as mail:
    # Creates a random address (e.g. qk3xh2m9ab@nembul.com) and logs in.
    account = mail.create_account()
    print("Email:", account.address)

    # Wait until a message arrives (matches sender and/or subject).
    message = mail.wait_for_message(from_="no-reply@github.com", timeout=120)
    print(message.subject)

    # Fetch the full message with body + attachments.
    message = mail.get_message(message.id)
    print(message.text)

    for attachment in message.attachments:
        data = mail.download_attachment(attachment)
        open(attachment.filename, "wb").write(data)

Features

  • Domains — list, pick an active public domain
  • Accounts — create (auto-generates address/password), login, get /me, delete
  • Messages — list/paginate, fetch full detail, mark seen, delete, download .eml source
  • Attachments — download attachment bytes
  • Pollingwait_for_message(...) with sender/subject/body filters and timeout
  • Real-timestream_messages() blocks on the Mercure SSE hub and yields an event every time a message lands

API

mail.get_domains(page=1)          # -> Paginated[Domain]
mail.get_domain(domain_id)        # -> Domain
mail.get_random_domain()          # -> Domain (active, non-private)

mail.create_account(address=None, password=None, autologin=True)  # -> Account
mail.login(address, password)     # -> Account (stores bearer token)
mail.get_token(address, password) # -> Token
mail.me()                         # -> Account
mail.get_account(account_id)      # -> Account
mail.delete_account(account_id=None)

mail.get_messages(page=1)         # -> Paginated[Message]
mail.iter_messages()              # -> Iterator[Message]
mail.get_message(message_id)      # -> Message (full)
mail.mark_seen(message_id)        # -> bool
mail.delete_message(message_id)
mail.get_source(source_id)        # -> dict (raw source)
mail.download_message(message_id) # -> bytes (.eml)
mail.download_attachment(attachment_or_url)  # -> bytes
mail.wait_for_message(from_=..., subject=..., contains=..., timeout=60)  # -> Message
mail.stream_messages()            # -> EventStream (real-time SSE)

Real-time events

Instead of polling you can block on the Mercure hub. Each event carries the account resource with an updated used counter, fired whenever a message is received:

from mailtm import MailTM

with MailTM() as mail:
    account = mail.create_account()
    for event in mail.stream_messages().iter_events():
        print("Account storage now:", event.account().used)

Errors

All failures raise APIError subclasses carrying the HTTP status code:

Exception Status Meaning
ValidationError 400/422 Malformed or invalid payload
AuthenticationError 401 Bad or missing bearer token
NotFoundError 404 Resource does not exist
RateLimitError 429 More than 8 requests/second
APIError other Any other API error

Notes

  • The general rate limit is 8 queries per second per IP address.
  • POST /accounts, GET /domains, and POST /token need no authentication; everything else requires a bearer token.
  • Deleting an account is permanent.

Download files

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

Source Distribution

mailtm_unofficial-0.1.0.tar.gz (13.4 kB view details)

Uploaded Source

Built Distribution

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

mailtm_unofficial-0.1.0-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

Details for the file mailtm_unofficial-0.1.0.tar.gz.

File metadata

  • Download URL: mailtm_unofficial-0.1.0.tar.gz
  • Upload date:
  • Size: 13.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.6

File hashes

Hashes for mailtm_unofficial-0.1.0.tar.gz
Algorithm Hash digest
SHA256 270dad1351a8b5ca4f3cf0a199cf26b1a08787c21f8fd1a464721ced8a32457d
MD5 bd6630b87de0ea8dea4dbb82787cbde2
BLAKE2b-256 263b2622493b129bb01765e64332eb13f1ac6d0cd70fbd207503da916aa041a6

See more details on using hashes here.

File details

Details for the file mailtm_unofficial-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for mailtm_unofficial-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f152da419a80a001b92247a83d7fad97ee9f067ac011a8066faa2444ed5758f2
MD5 f5a6432e409be4ab345515fdb8f55909
BLAKE2b-256 b78880499d7f79f93861362096af328b751beb271a092c0b6e7a6b6268a0c31c

See more details on using hashes here.

Supported by

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