Skip to content
This repository has been archived by the owner on Nov 29, 2023. It is now read-only.

Python class for use with Django to detect Disposable Emails

License

Notifications You must be signed in to change notification settings

aaronbassett/DisposableEmailChecker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

f6d63cd · Jan 18, 2018

History

57 Commits
Jan 18, 2018
Mar 21, 2017
Oct 13, 2015
Jan 18, 2018
Jan 18, 2018
Nov 4, 2015
Nov 4, 2015
Oct 13, 2015
Nov 4, 2015
Oct 13, 2015
Mar 21, 2017
Oct 13, 2015
Mar 21, 2017
Nov 4, 2015
Mar 21, 2017
Oct 13, 2015
Nov 4, 2015
Jan 18, 2018

Repository files navigation

============================= django-disposable-email-checker

PyPI version PyPI version Requirements Status

Django package to detect between ~890 & ~8,600 domains used by disposable email services. You can validate any email against our internal list of ~890 domains used by disposable email services. Optionally you can also check each domain against the Block-Disposable-Email.com API, covering ~8,600 domains.

Setup

Install the disposable email checker from PyPI

pip install django-disposable-email-checker

The disposable email checker comes with a list of ~890 emails. If you would like to provide your own email list create a function which returns a list of domains to block.

from disposable_email_checker.emails import email_domain_loader

def custom_email_domain_loader():
    # Anyone still using AOL will be too much of a customer service burden
    return [
        "aol.com",
    ] + email_domain_loader()

Then add the complete path including function name to your settings

DEC_LOADER = "my.package.custom_email_domain_loader"

If you would like to use the BDE integration add your API key to your Django settings

BDEA_APIKEY = "abcnotarealkey123"

optionally you can configure the BDE API timeout in seconds (default 5)

BDEA_TIMEOUT = 2

A default error message can be set globally for the validation checking (this is optional and if left blank it will default to _('Blocked email provider.')):

BDEA_MESSAGE = '<blocked email message>'

Adding to your models

Once you have completed setup add the DisposableEmailField to your models.

from disposable_email_checker.fields import DisposableEmailField

class MyModel(models.Model):
    email = DisposableEmailField()

The DisposableEmailField has a few optional arguments

  • whitelist - A list of emails which will always be allowed. Defaults to []
  • message - The error message used by ValidationError if validation fails. Defaults to _('Blocked email provider.')
  • code - The error code used by ValidationError if validation fails. Defaults to "invalid".

Using the validator

If you want to use the validator by itself

from django.core.exceptions import ValidationError
from disposable_email_checker.validators import validate_disposable_email

try:
    validate_disposable_email(email)
except ValidationError:
    pass