Skip to main content

A powerful library for creating and managing temporary email accounts

Project description

NowMail

NowMail is a powerful Python library for creating and managing temporary email accounts using the 1secmail.com API. NowMail offers asynchronous and synchronous methods for generating temporary mailboxes, checking messages, and fetching detailed message content. Additionally, it includes a periodic checker to automate mailbox monitoring.


Installation

Install NowMail using pip:

pip install nowmail

Features

  • Generate temporary email addresses: Create single or multiple random temporary email addresses.
  • Message checking and retrieval: Check for new messages and fetch message content.
  • Automated mailbox monitoring: Start a periodic checker to monitor mailboxes at defined intervals.
  • Error handling: Includes built-in exception handling for network and API issues.

Getting Started

Here's a quick guide to get started with NowMail.

Synchronous Example

from nowmail import generate, check, fetch

# Generate a temporary email address
email_addresses = generate(1)
print("Generated emails:", email_addresses)

# Parse login and domain from email
login, domain = email_addresses[0].split('@')

# Check the mailbox for messages
messages = check(login, domain)
if messages:
    message_id = messages[0].id
    # Fetch full message content
    message = fetch(login, domain, message_id)
    print("Message content:", message.body)
else:
    print("No new messages.")

Asynchronous Example

import asyncio
from nowmail.api.async_api import async_generate, async_check, async_fetch

async def main():
    # Generate email addresses asynchronously
    email_addresses = await async_generate(1)
    print("Generated emails:", email_addresses)

    login, domain = email_addresses[0].split('@')
    # Check for messages asynchronously
    messages = await async_check(login, domain)
    if messages:
        message_id = messages[0].id
        # Fetch full message content asynchronously
        message = await async_fetch(login, domain, message_id)
        print("Message content:", message.body)
    else:
        print("No new messages.")

asyncio.run(main())

Periodic Mailbox Checker

Use NowMail's start_checker to continuously monitor an email account and automatically retrieve messages as they arrive.

from nowmail import start_checker

# Start a periodic checker
checker = start_checker("example", "tempmail.com", interval=15, duration=60)
message = checker()
if message:
    print("New message:", message.body)
else:
    print("No new messages in the specified duration.")

Detailed API

NowMail provides several modules for handling temporary mailboxes and periodic message checking.

Core Modules

client.py

The TempMailClient class manages interactions with the tempmail API. It supports asynchronous mailbox generation, checking, and message fetching.

periodic_checker.py

PeriodicChecker automates email checking, enabling you to start a separate thread that continuously monitors an inbox for new messages.

exceptions.py

Custom exceptions to handle specific errors:

  • MailServiceError: Base exception for NowMail.
  • NetworkError: Raised for network-related issues.
  • APIError: Raised when the API returns an error response.

Configuration

You can configure NowMail using environment variables or the config.py module:

  • BASE_URL: Set the base URL of the API.
  • TIMEOUT: Define request timeout (default is 10 seconds).

Dependencies

NowMail requires the following dependencies:

aiohappyeyeballs==2.4.3
aiohttp==3.10.10
aiosignal==1.3.1
async-timeout==4.0.3
certifi==2024.8.30
charset-normalizer==3.4.0
email_validator==2.2.0
lxml==5.3.0
nest-asyncio==1.6.0
pydantic==2.9.2
requests==2.32.3
tenacity==9.0.0
yarl==1.16.0

Error Handling

NowMail includes robust error handling. If network issues or API errors occur, NowMail raises specific exceptions that provide details on the error type.

  • NetworkError: Raised if there’s a connectivity issue.
  • APIError: Raised if the API responds with an error message.

Testing

To run tests, you can use pytest. Make sure to install the development dependencies listed in install.me.

pytest --cov=nowmail tests/

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

nowmail-0.1.1.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

nowmail-0.1.1-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file nowmail-0.1.1.tar.gz.

File metadata

  • Download URL: nowmail-0.1.1.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.11

File hashes

Hashes for nowmail-0.1.1.tar.gz
Algorithm Hash digest
SHA256 193ea907c786a861505e398f205dc8cbc1b4b74c88efaaaf1c132161e47eab4d
MD5 8d655de07eca90750a86075188a803be
BLAKE2b-256 34aa1a44edd68ad862f9ac32602e069a1e0e0744004f5a79060937537b9a14d2

See more details on using hashes here.

File details

Details for the file nowmail-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: nowmail-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 10.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.11

File hashes

Hashes for nowmail-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 03c2a1df517f6cad0bd71b9347903cee680930f59af92217c05b4e70da8b4e1b
MD5 7eaa330d8925bde15356ed45663c7228
BLAKE2b-256 05cee5b069278a3462e487c852235aa098f7abfb72d93799e2a3e8f1c2974a19

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page