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.2.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: nowmail-0.1.2.tar.gz
  • Upload date:
  • Size: 9.4 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.2.tar.gz
Algorithm Hash digest
SHA256 597181708675a2f7c7ddd349d83ae4f11d6b6c2abdf475cc33199cb3aa2dd8fb
MD5 3b85af98f4fb80b44403c2458d4ffbc6
BLAKE2b-256 2151d462d09e7b8c7c90d8453ea2241ed1f016a798326793a6f6d92db179885c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: nowmail-0.1.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4e79700f95d93e9568997cad2c93142d97b5697c97cc3affed9133980920e94d
MD5 c4a14ace02282a8e25242f27062c093f
BLAKE2b-256 22ade7b3dec3789a29e7cc7c7036cd23cc73305d5dd123be267dea207d6360c1

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