Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added generic exception catcher so as to make validation more resilient. #52

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions validate_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def get_mx_ip(hostname):
return MX_DNS_CACHE[hostname]


def validate_email(email, check_mx=False, verify=False, debug=False, smtp_timeout=10):
def validate_email(email, check_mx=False, verify=False, debug=False, sending_email='', smtp_timeout=10):
"""Indicate whether the given string is a valid email address
according to the 'addr-spec' portion of RFC 2822 (see section
3.4.1). Parts of the spec that are marked obsolete are *not*
Expand Down Expand Up @@ -153,7 +153,7 @@ def validate_email(email, check_mx=False, verify=False, debug=False, smtp_timeou
if debug:
logger.debug(u'%s answer: %s - %s', mx[1], status, _)
continue
smtp.mail('')
smtp.mail(sending_email)
status, _ = smtp.rcpt(email)
if status == 250:
smtp.quit()
Expand All @@ -167,6 +167,9 @@ def validate_email(email, check_mx=False, verify=False, debug=False, smtp_timeou
except smtplib.SMTPConnectError:
if debug:
logger.debug(u'Unable to connect to %s.', mx[1])
except Exception as e:
if debug:
logger.debug(u'Unknown error: %s.', str(e))
return None
except AssertionError:
return False
Expand Down