Django package to detect ~890 domains used by disposable email services
Project description
=============================== django-disposable-email-checker
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.
This code was initially developed at: https://github.com/aaronbassett/DisposableEmailChecker However PyPI ownership has been transferred to https://github.com/jheld/DisposableEmailChecker and as such all future contributions are expected to be made to the new github repo.
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 django.db import 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
email = "emailaddress@readmetest.com" # replace with your own value
try:
validate_disposable_email(email)
except ValidationError:
pass
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django-disposable-email-checker-2.0.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6384b73ff6d974fe716441c4714e2c2ed638b988698f8bf73de902f8f3e47dad |
|
MD5 | b7471b23b46227e741ecee5261ab67a3 |
|
BLAKE2b-256 | 93d178bc08dcb1768ea488e02c2eacb774722a05d6b2d8e454e90bf0c4958915 |
Hashes for django_disposable_email_checker-2.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 58ebce5275e830567dae6dab9a599365acfa1aac71b376f73c30b5d084ac328e |
|
MD5 | d25e241f1a66a21570dc50acdcf44e77 |
|
BLAKE2b-256 | a4b0b2a64ac3a044800703b823258a975b184019ae390d0a29145ee2758f1525 |