Skip to main content

MailTM Python SDK

License: GPL v3

The MailTM Python SDK provides a simple and efficient way to interact with the Mail.tm API, which allows you to create temporary email accounts and manage messages programmatically. This SDK is ideal for automated testing, handling email verifications, and other scenarios where disposable email addresses are useful.

Table of Contents

Introduction

MailTM is a temporary email service that provides disposable email addresses. This SDK allows developers to interact with the MailTM API to create temporary email accounts, retrieve and manage messages, and delete accounts when they are no longer needed.

Installation

To install the MailTM Python SDK, simply use pip:

pip install mailtm-python

To install nightly builds, use the following command:

pip install git+https://github.com/viperadnan-git/mailtm-python-sdk.git --force-reinstall

Alternatively, you can clone the repository and install the dependencies manually:

git clone https://github.com/viperadnan-git/mailtm-python-sdk.git
cd mailtm-python-sdk
pip install -r requirements.txt

Usage

Creating an Account

To create a new temporary email account, you can use the create_account method. Here's an example:

from mailtm import MailTMClient

# Fetch available domains
domains = MailTMClient.get_domains()

# Create a new account using one of the domains
email_address = f"mytempemail@{domains[0].domain}"
password = "supersecretpassword"

client = MailTMClient.create_account(address=email_address, password=password)
print(f"Account created with email: {client.address}")

Fetching Domains

To fetch the list of available domains that can be used for creating temporary email addresses:

domains = MailTMClient.get_domains()
for domain in domains:
    print(f"Domain: {domain.domain}")

Retrieving Messages

After creating an account and authenticating, you can retrieve messages for that account:

# Fetch messages
messages = client.get_messages()
for message in messages:
    print(f"From: {message.from_.address}, Subject: {message.subject}")

Deleting Messages

You can delete a specific message by its ID:

message_id = messages[0].id
client.delete_message(message_id)
print(f"Message {message_id} deleted.")

Methods

The following methods are provided by the MailTMClient class:

  • MailTMClient.get_domains(page: int = 1, proxies: Optional[Dict[str, str]] = None) -> List[Domain]: Fetch the available domains for creating an account.

    Example:

    domains = MailTMClient.get_domains(proxies={"http": "http://proxy.example.com:8080"})
    for domain in domains:
        print(f"Domain: {domain.domain}")
    
  • MailTMClient.get_domain_by_id(domain_id: str, proxies: Optional[Dict[str, str]] = None) -> Domain: Retrieve details of a specific domain by its ID.

    Example:

    domain = MailTMClient.get_domain_by_id("some-domain-id", proxies={"http": "http://proxy.example.com:8080"})
    print(f"Domain: {domain.domain}")
    
  • MailTMClient.create_account(address: str, password: str, proxies: Optional[Dict[str, str]] = None) -> Account: Create a new temporary email account.

    Example:

    account = MailTMClient.create_account("user@domain.com", "password", proxies={"http": "http://proxy.example.com:8080"})
    print(f"Account created with email: {account.address}")
    
  • MailTMClient.get_token(address: str, password: str) -> TokenResponse: Authenticate and obtain a token for an account.

    Example:

    token_response = MailTMClient.get_token("mytempemail@mail.tm", "supersecretpassword")
    print(f"Token: {token_response.token}")
    
  • MailTMClient.get_account(token: Optional[str] = None) -> Account: Get details of the authenticated account.

    Example:

    account = client.get_account()
    print(f"Account: {account.address}")
    
  • MailTMClient.get_account_by_id(account_id: str) -> Account: Get details of an account by its ID.

    Example:

    account = client.get_account_by_id("some-account-id")
    print(f"Account: {account.address}")
    
  • MailTMClient.delete_account(account_id: str) -> bool: Delete an account by its ID.

    Example:

    success = client.delete_account("some-account-id")
    if success:
        print("Account successfully deleted.")
    
  • MailTMClient.get_messages(page: int = 1) -> List[Message]: Retrieve messages for the authenticated account.

    Example:

    messages = client.get_messages()
    for message in messages:
        print(f"From: {message.from_.address}, Subject: {message.subject}")
    
  • MailTMClient.get_message_by_id(message_id: str) -> MessageDetail: Retrieve a specific message by its ID.

    Example:

    message_detail = client.get_message_by_id("some-message-id")
    print(f"Message from: {message_detail.from_.address}, Subject: {message_detail.subject}")
    
  • MailTMClient.delete_message(message_id: str) -> bool: Delete a specific message by its ID.

    Example:

    success = client.delete_message("some-message-id")
    if success:
        print("Message successfully deleted.")
    
  • MailTMClient.mark_message_as_read(message_id: str) -> MessageDetail: Mark a message as read.

    Example:

    message_detail = client.mark_message_as_read("some-message-id")
    print(f"Message read status: {message_detail.seen}")
    
  • MailTMClient.get_message_source(message_id: str) -> MessageSource: Get the raw source of a message.

    Example:

    message_source = client.get_message_source("some-message-id")
    print(f"Message source: {message_source.data}")
    
  • MailTMClient.get_message_attachments(message_id: str) -> List[Attachment]: Get the attachments of a specific message.

    Example:

    attachments = client.get_message_attachments("some-message-id")
    for attachment in attachments:
        print(f"Attachment: {attachment.filename}")
    
  • MailTMClient.get_attachment(message_id: str, attachment_id: str) -> Attachment: Get a specific attachment by its ID.

    Example:

    attachment = client.get_attachment("some-message-id", "some-attachment-id")
    print(f"Attachment filename: {attachment.filename}")
    

Contributing

We welcome contributions to the MailTM Python SDK! If you find a bug or want to add a feature, feel free to open an issue or submit a pull request.

License

This project is licensed under the GNU General Public License v3 (GPLv3) - see the LICENSE file for details.


Note: This SDK is designed for use with the MailTM API. Please ensure you use this SDK responsibly and adhere to MailTM's terms of service. Misuse of this SDK for illegal activities is strictly prohibited.

Metadata

Release files for mailtm-python 0.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 mailtm-python 0.1.0
File Size Uploaded
mailtm_python-0.1.0.tar.gz 18.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mailtm-python 0.1.0
File Interpreter ABI Platform
mailtm_python-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 37.4 kB

Release files / mailtm_python-0.1.0.tar.gz

Download URL mailtm_python-0.1.0.tar.gz
Size 18.6 kB
Tags Source
SHA-256 checksum
How to use checksums
4224dabe3aafc163aac96c7bb6d41268b495c09becbd00060b53d56ba9ca6775
BLAKE2b-256 checksum
How to use checksums
a47e34e2e3c27fd54d9aa854f7cf3d2a0633df2297c5560cb774ac5bba780036
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.5

Release files / mailtm_python-0.1.0-py3-none-any.whl

Download URL mailtm_python-0.1.0-py3-none-any.whl
Size 18.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2d482ccd0d760b2ea16ff6a0b43402822a232a439405c0977f1f4b8027fe563e
BLAKE2b-256 checksum
How to use checksums
caaeb1b770b0010e289f8e999c820677b93a44bbbbd45568e8d761d1bde3e38e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.5

Release history Release notifications | RSS feed

This release

0.1.0 This release

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