MailTmWrapper is a Python library designed to interact with the Mail.TM API, providing an easy-to-use interface for creating temporary email accounts and managing email messages programmatically. This wrapper simplifies operations such as generating tokens, retrieving messages, and managing accounts.
- Create and manage temporary email accounts.
- Generate tokens for authenticated API requests.
- Fetch, read, and delete email messages.
- Retrieve domains and account information.
- Minimal dependencies and easy integration.
- Supports custom proxy configurations for network flexibility.
To install the package locally, clone the repository and run:
pip install .You can also install it via pip from PyPI:
pip install MailTmWrapperfrom mailtmwrapper import MailTMYou can create a temporary email account using the create_account method:
token = MailTM().create_token(email, password)
mail = MailTM(token) # token is optional
# Create a new temporary email account
account = mail.create_account()
email = account['address']
password = account['password']
print(f"Temporary email: {email}")If you prefer, you can specify a custom email address and password:
account = mail.create_account(email="custom_address@domain.com", password="CustomPassword123?")To perform authenticated operations, generate a token using the create_token method:
token = mail.create_token(email, password)
print(f"Generated token: {token}")Retrieve the list of email messages associated with your account:
messages = mail.get_messages()
print("Messages:", messages)You can also fetch specific message details by ID:
message_id = messages['hydra:member'][0]['id']
message_details = mail.get_message_by_id(message_id)
print("Message details:", message_details)Delete an email message by its ID:
message_id = "your_message_id"
success, status_code = mail.delete_message(message_id)
if success:
print("Message deleted successfully.")
else:
print(f"Failed to delete message. Status code: {status_code}")Get account details using the get_me method:
account_info = mail.get_me()
print("Account info:", account_info)Delete the temporary email account:
success, status_code = mail.delete_account(account_id="your_account_id")
if success:
print("Account deleted successfully.")
else:
print(f"Failed to delete account. Status code: {status_code}")Fetch the list of domains supported by Mail.TM:
domains = mail.get_domains()
print("Domains:", domains)Get details of a specific domain by its ID:
domain_id = "your_domain_id"
domain_details = mail.get_domain_by_id(domain_id)
print("Domain details:", domain_details)Here is a full example combining account creation, token generation, and email fetching:
from mailtm_wrapper import MailTM
mail = MailTM()
# Create a temporary account
account = mail.create_account()
email = account['address']
password = account['password']
print(f"Temporary email: {email}")
# Generate a token
token = mail.create_token(email, password)
print(f"Generated token: {token}")
# Fetch messages
messages = mail.get_messages()
print("Messages:", messages)
# Retrieve message details
if messages['hydra:member']:
message_id = messages['hydra:member'][0]['id']
message_details = mail.get_message_by_id(message_id)
print("Message details:", message_details)
# Delete the account
success, status_code = mail.delete_account(account_id=account['id'])
if success:
print("Account deleted successfully.")
else:
print(f"Failed to delete account. Status code: {status_code}")MailTmWrapper requires:
requeststo send requests to the Mail.TM API. To install dependencies manually, run:
pip install requestsMailTmWrapper is licensed under the MIT License. See the LICENSE file for more details. Mail.TM.
Contributions are welcome! Feel free to fork the repository, make changes, and submit a pull request.
MailTmWrapper is developed and maintained by sexfrance. Mail.TM is developed and maintained by MailTM.