this package can provide some email validators with which users can validate their project emails far easily
your module will be installed by PYPI
pip install email-domain-verification
from email_domain_verification import Email, EmailVerifier
from email_domain_verification.validators import BlackDomainListValidator
# you can import any of these validators or write your own validator
# (
# BlackDomainListValidator,
# DomainExtensionValidator,
# LengthValidator,
# MultiDotValidator,
# SafeDomainValidator,
# SafeDomainValidatorOnline,
# )
email = Email("hello@gmail.com")
black_email_list = [
"xyz-mail.com",
"tempmail.com",
"temp.com",
"mail-temp.org",
# ...
]
validators = [
BlackDomainListValidator(black_email_list),
]
verifier = EmailVerifier(email)
verifier.verify(validators)
from email_domain_verification import Email, EmailVerifier
from email_domain_verification.validators import BlackDomainListValidator
email = Email("hello@gmail.com")
black_email_list = [
"xyz-mail.com",
"tempmail.com",
# ...
]
validators = [
BlackDomainListValidator(black_email_list),
]
verifier = EmailVerifier(email)
validated: bool = verifier.verify(validators, raise_exception=False)
# validated == True => email is safe | validated == False => email is unsafe
from email_domain_verification import Email, EmailVerifier
from email_domain_verification.interfaces import ValidatorInterface
from email_domain_verification.validators import LengthValidator
class CustomValidator(ValidatorInterface):
__criterion: typing.Type
def __init__(self, criterion: typing.Type) -> None:
self.__criterion = criterion
def validate_criterion(self) -> None:
# validate __criterion
pass
def check(self, email: Email) -> bool:
self.validate_criterion()
# check email.value
# example: len(email.value) > self.__criterion: return True
validate = True
if not validate:
raise ValueError("The Error Message")
return True
email = Email("hello@gmail.com")
validators = [
BlackDomainListValidator(black_email_list),
CustomValidator(10),
]
verifier = EmailVerifier(email)
verifier.verify(validators)