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:
TooManyRequestsRegistrationFailedTokenErrorFetchMessagesFailedFetchAccountFailed
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f52b896c11530e9a2a08c58e4e49945309d3de28c7e90c7cb24c1aff4f2609a3
|
|
| MD5 |
2b4a838ed322c257f6951c1788651dc6
|
|
| BLAKE2b-256 |
a020447b57140db75c134ea58d5a2eb0995f8f287afeee854213a8cf21bae42b
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b63bcba0e15caf564bd089e4bfb4787eed874f8a8d7f7da26853b267db1e0f2d
|
|
| MD5 |
7298ef64706aa7de294f6528c91833b5
|
|
| BLAKE2b-256 |
7af809a076b29d7f56bba87a888fd8bb603b4fa83c17c62a7d9b73258b822fa9
|