Skip to main content

Detect disposable email addresses with domain, MX, pattern, and RBL checks.

Project description

Temp Email Filter

Temp Email Filter is a Python package for detecting disposable email addresses. It performs comprehensive checks including known disposable domains, trusted provider validation, email patterns, MX record validation, blocked MX hosts, and DNS-based RBL (Real-time Blackhole List) services.

Features

  • Trusted provider check: Immediately validates emails from known legitimate providers (Gmail, Yahoo, etc.)
  • Disposable domain detection: Checks against known temporary email services
  • Pattern analysis: Identifies suspicious email patterns (excludes legitimate + aliases)
  • MX record validation: Verifies domain has valid mail servers
  • RBL checking: Queries reputation databases using proper IP-based lookups
  • Intelligent caching: Caches both positive and negative results for performance
  • DNS timeouts: Prevents hanging on slow DNS queries
  • Input validation: Normalizes and validates email format before processing

Install

pip install temp-email-filter

For local development from a clone:

git clone <your-repo-url>
cd temp_email_filter
python -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"

Basic Usage

from temp_email_filter import check_email

result = check_email("test@gmail.com")
print(f"Email: {result.email}")
print(f"Is disposable: {result.is_disposable}")
print(f"Reason: {result.reason}")

if result.is_disposable:
    print("This email should be rejected")
else:
    print("This email is acceptable")

If you only need the original tuple style:

from temp_email_filter import is_disposable_email

is_disposable, reason = is_disposable_email("test@gmail.com")

Django Example

from django.core.exceptions import ValidationError
from temp_email_filter import check_email


def validate_non_disposable_email(value):
    result = check_email(value)
    if result.is_disposable:
        raise ValidationError(result.reason)

Use the validator in a model or serializer field.

FastAPI Example

This package does not start a FastAPI server. Add it to your own FastAPI app:

from fastapi import FastAPI, HTTPException
from temp_email_filter import check_email

app = FastAPI()


@app.get("/email-checker")
def email_checker(email: str):
    result = check_email(email)
    if result.reason.startswith("Invalid email"):
        raise HTTPException(status_code=400, detail=result.reason)

    return {
        "email": result.email,
        "is_disposable": result.is_disposable,
        "reason": result.reason,
    }

Running As A Service

This project is package-only. To run it as a service, install it inside your own Django, FastAPI, Flask, worker, or microservice project and call check_email() from your route, form validation, serializer, or background job.

Configuration

The cache directory defaults to .email_cache. Override it with:

export TEMP_EMAIL_FILTER_CACHE_DIR=/tmp/temp-email-filter-cache

Recent Improvements (v0.1.1)

  • Fixed RBL checking: Now properly queries MX record IPs instead of domains
  • Improved pattern matching: Removed false positive for legitimate + aliases (john+work@gmail.com)
  • Enhanced caching: Now caches both disposable and legitimate results
  • Better logic flow: Trusted providers checked first, bypassing expensive DNS operations
  • DNS timeouts: Added configurable timeouts to prevent hanging queries
  • Transient error handling: Avoids caching temporary DNS failures

Development

pip install -e ".[dev]"
pytest

Publishing

Maintainer release steps are documented in docs/PYPI.md.

License

MIT

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

temp_email_filter-0.1.1.tar.gz (9.2 kB view details)

Uploaded Source

Built Distribution

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

temp_email_filter-0.1.1-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: temp_email_filter-0.1.1.tar.gz
  • Upload date:
  • Size: 9.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.9

File hashes

Hashes for temp_email_filter-0.1.1.tar.gz
Algorithm Hash digest
SHA256 f873538cff0941affaef5020e65d5cecebd6b38fac2448aa5c616e2b1290c29f
MD5 c3349c542c8802314fc2fa0dee2f9023
BLAKE2b-256 75ab26de5995507c3fcf5d3ba50487b32756e2486e6692c41bdfa70f9f60eba4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for temp_email_filter-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f2edb5c7c45f7514c80f55620da997e3b965579c2fb7b9e36240b1542dffd3c4
MD5 b7da5573947edf2f8932448e05e89147
BLAKE2b-256 58e6cf864fa7acf64a06f8a7d14e54e4976c5a3c2a683af722a74e45c6c6a7ae

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