Changed from mx to check_mx

This commit is contained in:
Syrus Akbary 2012-04-07 23:13:13 +02:00
parent 8fcf614de6
commit 86ae68a53c
3 changed files with 6 additions and 5 deletions

1
.gitignore vendored
View file

@ -2,3 +2,4 @@
build build
dist dist
MANIFEST MANIFEST
*.egg-info

View file

@ -36,13 +36,13 @@ Checking domain has SMTP Server
Check if the host has SMPT Server:: Check if the host has SMPT Server::
from validate_email import validate_email from validate_email import validate_email
is_valid = validate_email('example@example.com',mx=True) is_valid = validate_email('example@example.com',check_mx=True)
Verify email exists Verify email exists
------------------- -------------------
Check if the host has SMPT Server and the email exists in the server:: Check if the host has SMPT Server and the email really exists::
from validate_email import validate_email from validate_email import validate_email
is_valid = validate_email('example@example.com',verify=True) is_valid = validate_email('example@example.com',verify=True)

View file

@ -81,7 +81,7 @@ ADDR_SPEC = LOCAL_PART + r'@' + DOMAIN # see 3.4.1
# A valid address will match exactly the 3.4.1 addr-spec. # A valid address will match exactly the 3.4.1 addr-spec.
VALID_ADDRESS_REGEXP = '^' + ADDR_SPEC + '$' VALID_ADDRESS_REGEXP = '^' + ADDR_SPEC + '$'
def validate_email(email, mx=False,verify=False): def validate_email(email, check_mx=False,verify=False):
"""Indicate whether the given string is a valid email address """Indicate whether the given string is a valid email address
according to the 'addr-spec' portion of RFC 2822 (see section according to the 'addr-spec' portion of RFC 2822 (see section
@ -92,8 +92,8 @@ def validate_email(email, mx=False,verify=False):
to be in use as of 2011.""" to be in use as of 2011."""
try: try:
assert re.match(VALID_ADDRESS_REGEXP, email) is not None assert re.match(VALID_ADDRESS_REGEXP, email) is not None
mx |= verify check_mx |= verify
if mx: if check_mx:
if not DNS: raise Exception('For check the mx records or check if the email exists you must have installed pyDNS python package') if not DNS: raise Exception('For check the mx records or check if the email exists you must have installed pyDNS python package')
DNS.DiscoverNameServers() DNS.DiscoverNameServers()
hostname = email[email.find('@')+1:] hostname = email[email.find('@')+1:]