TestMailHelper is a Python package designed for easy interaction with the Testmail.app API. It simplifies the process of retrieving email lists and fetching specific emails using the API.
- Retrieve a detailed list of emails from the Testmail API.
- Fetch a specific email by its ID.
- Retrieve emails filtered by a specific tag.
You can install it using pip:
pip install TestMailHelper
Here's a basic example of how to use the TMClient
class provided by the TestMailHelper
package:
from testmailhelper import TMClient
def main():
client = TMClient(
api_key='your_api_key',
namespace='your_namespace'
)
# Get a list of emails
emails = client.get_emails_list()
print("Email List:")
for email in emails:
print(email)
# Get a specific email by ID
email_id = 'some_email_id'
email = client.get_email_by_id(email_id)
if email:
print("Email Details:")
print(email)
else:
print(f"No email found with ID: {email_id}")
# Get emails by tag
tag = 'some_tag'
tagged_emails = client.get_emails_by_tag(tag)
print(f"Emails with tag '{tag}':")
for email in tagged_emails:
print(email)
if __name__ == "__main__":
main()
Initialize the TMClient
with your API key and namespace.
api_key
(str): Your API key for the Testmail API.namespace
(str): The namespace for the Testmail API.
Retrieve a list of emails from the Testmail API.
- Returns: A list of dictionaries, each representing an email with keys:
'from'
,'subject'
,'tag'
,'timestamp'
,'id'
. - Raises:
requests.exceptions.RequestException
if the request fails.
Retrieve a specific email by its ID.
email_id
(str): The ID of the email to retrieve.- Returns: A dictionary representing the email, or
None
if not found. - Raises:
requests.exceptions.RequestException
if the request fails.
Retrieve a list of emails with a specific tag.
tag
(str): The tag to filter emails by.- Returns: A list of dictionaries, each representing an email with keys:
'from'
,'subject'
,'tag'
,'timestamp'
,'id'
. - Raises:
requests.exceptions.RequestException
if the request fails.
Contributions are welcome! Please open an issue or submit a pull request if you have suggestions or improvements.
This project is licensed under the MIT License. See the LICENSE file for details.
For questions or support, please contact Muhammad Ali.