Skip to main content

mailpytm

A Python client library for the mail.tm temporary email service API.

This package allows you to easily create disposable email accounts, fetch messages, manage tokens, and interact with the mail.tm API seamlessly.

Features

  • Create and register temporary email accounts
  • Fetch and read emails
  • Poll and wait for specific messages
  • Mark emails as read and delete them
  • Manage authentication tokens automatically

Installation

pip install mailpytm

Usage

from mailpytm import MailTMApi

def usage_example():
    print("=== MailTMApi Usage Example ===")

    # 1️⃣ Create a new email account
    account = MailTMApi.create_email()
    print(f"Created account: {account.address}")
    
    # 2️⃣ Get account token
    print(f"Token: {account.token[:10]}...")  # truncated

    # 3️⃣ Get account info
    info = account.account_info
    print(f"Account ID: {account.id}")
    print(f"Account email: {info.get('address')}")

    # 4️⃣ Fetch current messages
    print(f"Current messages: {len(account.messages)}")

    # 5️⃣ Wait for new message (subject filter optional)
    try:
        print("Waiting for new messages (timeout 30s)...")
        new_msg = account.wait_for_new_message(subject_contains=None, timeout=30)
        print(f"New message received: {new_msg.get('id')}, subject: {new_msg.get('subject')}")
    except TimeoutError:
        print("No new messages arrived during the timeout.")

    # 6️⃣ Mark first message as read if available
    if account.messages:
        msg_id = account.messages[0]["id"]
        seen = account.mark_message_as_read(msg_id)
        print(f"Message {msg_id} marked as read: {seen}")

    # 7️⃣ Delete first message if available
    if account.messages:
        msg_id = account.messages[0]["id"]
        deleted = account.delete_message(msg_id)
        print(f"Message {msg_id} deleted: {deleted}")

    # 8️⃣ Use context manager for temporary accounts
    with MailTMApi.create_email() as temp_account:
        print(f"Temporary account created: {temp_account.address}")
        print(f"Token: {temp_account.token[:10]}...")

    # 9️⃣ Delete original account
    deleted = account.delete_account()
    print(f"Original account deleted: {deleted}")

    print("=== Usage example finished ===")

if __name__ == "__main__":
    usage_example()

Exceptions

Exceptions are available under mailpytm.exceptions for fine-grained error handling:

  • TooManyRequests
  • RegistrationFailed
  • TokenError
  • FetchMessagesFailed
  • FetchAccountFailed

Contributing

Contributions, issues, and feature requests are welcome! Feel free to check the issues page.

License

This project is licensed under the MIT License.

Metadata

Release files for mailpytm 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mailpytm 1.1.0
File Size Uploaded
mailpytm-1.1.0.tar.gz 6.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mailpytm 1.1.0
File Interpreter ABI Platform
mailpytm-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 12.7 kB

Release files / mailpytm-1.1.0.tar.gz

Download URL mailpytm-1.1.0.tar.gz
Size 6.1 kB
Tags Source
SHA-256 checksum
How to use checksums
f52b896c11530e9a2a08c58e4e49945309d3de28c7e90c7cb24c1aff4f2609a3
BLAKE2b-256 checksum
How to use checksums
a020447b57140db75c134ea58d5a2eb0995f8f287afeee854213a8cf21bae42b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Release files / mailpytm-1.1.0-py3-none-any.whl

Download URL mailpytm-1.1.0-py3-none-any.whl
Size 6.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b63bcba0e15caf564bd089e4bfb4787eed874f8a8d7f7da26853b267db1e0f2d
BLAKE2b-256 checksum
How to use checksums
7af809a076b29d7f56bba87a888fd8bb603b4fa83c17c62a7d9b73258b822fa9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files

1.0.0

2 release files

0.9.93

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page