Skip to main content

Python wrapper for mail.tm disposable email service

Project description

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.

Project details


Download files

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

Source Distribution

mailpytm-1.1.0.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

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

mailpytm-1.1.0-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file mailpytm-1.1.0.tar.gz.

File metadata

  • Download URL: mailpytm-1.1.0.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for mailpytm-1.1.0.tar.gz
Algorithm Hash digest
SHA256 f52b896c11530e9a2a08c58e4e49945309d3de28c7e90c7cb24c1aff4f2609a3
MD5 2b4a838ed322c257f6951c1788651dc6
BLAKE2b-256 a020447b57140db75c134ea58d5a2eb0995f8f287afeee854213a8cf21bae42b

See more details on using hashes here.

File details

Details for the file mailpytm-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: mailpytm-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for mailpytm-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b63bcba0e15caf564bd089e4bfb4787eed874f8a8d7f7da26853b267db1e0f2d
MD5 7298ef64706aa7de294f6528c91833b5
BLAKE2b-256 7af809a076b29d7f56bba87a888fd8bb603b4fa83c17c62a7d9b73258b822fa9

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 Pingdom Monitoring Sentry Error logging StatusPage Status page