Skip to main content

Official Python SDK for the EvilMail API

Project description

EvilMail Logo

EvilMail Python SDK

Official Python client library for the EvilMail disposable email API

PyPI Version Python Versions Monthly Downloads License: MIT Checked with mypy

InstallationQuick StartAsyncAPI ReferenceError HandlingDocumentation


The EvilMail Python SDK provides a modern, fully-typed interface for integrating temporary email, disposable email addresses, email verification code extraction, inbox management, and custom domain email services into your Python applications. Supports both synchronous and asynchronous clients with complete type hints and dataclass response models.

Features

  • Sync + Async Clients — Choose EvilMail or AsyncEvilMail based on your application architecture
  • Temporary Email — Create anonymous disposable email addresses with configurable TTL
  • Email Verification Codes — Auto-extract OTP codes from Google, Facebook, Instagram, TikTok, Discord, Twitter, LinkedIn, iCloud
  • Account Management — Full CRUD for persistent email accounts on custom domains
  • Inbox Access — Read emails, list messages, fetch full HTML & plain text content
  • Random Email Generator — Batch create random email accounts with auto-generated passwords
  • Domain Management — List free, premium, and custom email domains
  • Fully Typed — Complete type hints with py.typed marker, mypy --strict compatible
  • Dataclass Models — All API responses parsed into frozen dataclasses
  • Context Manager Support — Automatic resource cleanup with with / async with
  • Built on httpx — Modern, high-performance HTTP client with connection pooling

Installation

pip install evilmail

Requires Python 3.9+.

Quick Start

from evilmail import EvilMail

client = EvilMail("your-api-key")

# Create a temporary disposable email address
temp = client.temp_email.create(domain="evilmail.pro", ttl_minutes=60)
print(f"Temporary email: {temp.email}")
print(f"Session token: {temp.session_token}")
print(f"Expires at: {temp.expires_at}")

# Check session status
session = client.temp_email.check_session(temp.session_token)

# Read a specific message from temp inbox
message = client.temp_email.get_message(temp.session_token, uid=1)
print(f"Subject: {message.subject}")

# List inbox messages from a persistent account
messages = client.inbox.list("user@yourdomain.com")
for msg in messages:
    print(f"{msg.sender}: {msg.subject}")

# Extract a Google verification code automatically
code = client.verification.get_code("google", "user@yourdomain.com")
print(f"Verification code: {code.code}")

# Batch create random email accounts
batch = client.random_email.create_batch("yourdomain.com", count=5, password_length=20)
for entry in batch.emails:
    print(f"{entry.email}: {entry.password}")

client.close()

Async Usage

import asyncio
from evilmail import AsyncEvilMail

async def main():
    async with AsyncEvilMail("your-api-key") as client:
        # Create temp email
        temp = await client.temp_email.create(domain="evilmail.pro")
        print(f"Email: {temp.email}")

        # Extract verification code
        code = await client.verification.get_code("google", "user@yourdomain.com")
        print(f"Code: {code.code}")

        # List accounts
        accounts = await client.accounts.list()
        for acct in accounts:
            print(f"Account: {acct.email}")

asyncio.run(main())

Authentication

All requests require an API key via the X-API-Key header. Get your key from the EvilMail dashboard.

# Basic
client = EvilMail("your-api-key")

# With custom settings
client = EvilMail(
    "your-api-key",
    base_url="https://evilmail.pro",  # default
    timeout=60.0,                      # seconds, default 30
)

Context Managers

Both clients support context managers for automatic resource cleanup:

# Synchronous
with EvilMail("your-api-key") as client:
    accounts = client.accounts.list()

# Asynchronous
async with AsyncEvilMail("your-api-key") as client:
    accounts = await client.accounts.list()

API Reference

Temporary Email

Create anonymous, disposable email addresses with automatic expiration. Perfect for sign-up verification, automated testing, and privacy protection.

client.temp_email.create(*, domain=None, ttl_minutes=None)

Create a new temporary email address.

Parameter Type Required Description
domain str No Preferred domain for the disposable address
ttl_minutes int No Time-to-live in minutes

Returns: TempEmailemail, domain, session_token, ttl_minutes, expires_at

client.temp_email.check_session(token)

Check if a temporary email session is still active.

client.temp_email.get_message(token, uid)

Read a specific message from a temp email inbox.

Parameter Type Required Description
token str Yes Session token from create()
uid int Yes Message UID

Returns: Message

client.temp_email.delete(token)

Permanently delete a temporary email session.


Accounts

Manage persistent email accounts on custom domains.

client.accounts.list()

Returns: list[Account]email, domain, created_at

client.accounts.create(email, password)

Returns: CreatedAccountemail

client.accounts.delete(emails)

Returns: DeleteResultdeleted_count

client.accounts.change_password(email, new_password)


Inbox

Read emails from persistent account inboxes with full message content.

client.inbox.list(email)

Returns: list[InboxMessage]uid, sender, subject, date, seen

client.inbox.get_message(uid, email)

Returns: Messageuid, sender, subject, text, html, date, seen


Verification Codes

Automatically extract OTP verification codes from emails sent by popular services.

client.verification.get_code(service, email)

Supported services: facebook, twitter, google, icloud, instagram, tiktok, discord, linkedin

Returns: VerificationCodecode, service, email, sender, subject, date


Random Email

Generate random email accounts with secure auto-generated credentials.

client.random_email.preview()

Returns: RandomEmailPreviewusername, email, password, domain

client.random_email.create_batch(domain, *, count=None, password_length=None)

Returns: RandomEmailBatchcount, emails: list[RandomEmailEntry]


Domains

List available email domains by tier.

client.domains.list()

Returns: Domainsfree, premium, customer, package_type, authenticated


Response Models

All API responses are parsed into frozen dataclasses with complete type hints:

Model Fields
TempEmail email, domain, session_token, ttl_minutes, expires_at
InboxMessage uid, sender, subject, date, seen
Account email, domain, created_at
CreatedAccount email
DeleteResult deleted_count
Message uid, sender, subject, text, html, date, seen
VerificationCode code, service, email, sender, subject, date
RandomEmailPreview username, email, password, domain
RandomEmailEntry email, password
RandomEmailBatch count, emails
Domains free, premium, customer, package_type, authenticated

Error Handling

The SDK raises typed exceptions for precise error handling:

from evilmail import (
    EvilMailError,       # Base exception for all SDK errors
    APIError,            # Non-success HTTP response from the API
    AuthenticationError, # 401 Unauthorized — invalid API key
    ForbiddenError,      # 403 Forbidden — insufficient permissions
    NotFoundError,       # 404 Not Found — resource does not exist
    RateLimitError,      # 429 Too Many Requests — slow down
    ServerError,         # 5xx Server Error — API-side issue
    ConnectionError,     # Network connectivity issues
    TimeoutError,        # Request timeout exceeded
    ValidationError,     # Invalid parameters (client-side validation)
)

try:
    code = client.verification.get_code("google", "user@yourdomain.com")
    print(f"Your code: {code.code}")
except NotFoundError:
    print("No verification email found yet")
except RateLimitError as exc:
    print(f"Rate limited: {exc.message}")
except AuthenticationError:
    print("Invalid API key — check your credentials")
except EvilMailError as exc:
    print(f"Error: {exc}")

Use Cases

  • Automated Testing & QA — Generate disposable email addresses for end-to-end test suites with pytest, unittest, or Robot Framework
  • Web Scraping & Automation — Create temp emails for sign-up flows in Selenium, Playwright, or Scrapy pipelines
  • Email Verification Bots — Automatically extract OTP codes from Google, Facebook, Instagram, and more
  • Account Provisioning — Bulk create and manage email accounts for SaaS platforms
  • Privacy & Anonymity — Use anonymous email addresses to protect user identity
  • CI/CD Pipelines — Integrate email testing into GitHub Actions, GitLab CI, or Jenkins workflows
  • Async Web Applications — Native async support for FastAPI, aiohttp, and Django async views
  • Data Science & Research — Programmatic email generation for data collection workflows

Related SDKs

Language Package Repository
Node.js evilmail Evil-Mail/evilmail-node
PHP evilmail/evilmail-php Evil-Mail/evilmail-php
Python evilmail Evil-Mail/evilmail-python
Go evilmail-go Evil-Mail/evilmail-go

Links

License

MIT

Support

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

evilmail-1.0.0.tar.gz (13.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

evilmail-1.0.0-py3-none-any.whl (18.4 kB view details)

Uploaded Python 3

File details

Details for the file evilmail-1.0.0.tar.gz.

File metadata

  • Download URL: evilmail-1.0.0.tar.gz
  • Upload date:
  • Size: 13.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for evilmail-1.0.0.tar.gz
Algorithm Hash digest
SHA256 370467331c2c90baff13c433be7beee031b412dcc6fa3436751492bb6be224b7
MD5 84a7359d2bc82437bd9f9fa22960b99f
BLAKE2b-256 79e4ab80165510fc2633cf484756d2ab0c70d969b6326ea4d085b228e16a8c14

See more details on using hashes here.

File details

Details for the file evilmail-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: evilmail-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 18.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for evilmail-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 277e05488db09f5bc8a603135ae1eea7e591c018a251c515df78a78d559b0a8c
MD5 958f47ead6dc872f0f5f6ee7fa2e9520
BLAKE2b-256 b8a66dacebdc8dcbea8ac82b0f5e4733bef4b2187faa93cf0013546d723b0669

See more details on using hashes here.

Supported by

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