Fix MX record exception

This commit is contained in:
László Károlyi 2019-03-02 02:45:00 +01:00
parent 01b2d9030c
commit 03a7a75600
Signed by: karolyi
GPG Key ID: 2DCAF25E55735BFE
1 changed files with 6 additions and 5 deletions

View File

@ -17,13 +17,11 @@ def _get_domain_from_email_address(email_address):
raise ValueError('Invalid email address')
def _get_mx_records(domain):
def _get_mx_records(domain: str) -> list:
try:
records = dns.query(domain, 'MX')
except dns.NXDOMAIN:
raise ValueError('Domain {} does not seem to exist')
except Exception:
raise NotImplementedError('Feature not yet implemented')
raise ValueError(f'Domain {domain} does not seem to exist')
return [str(x.exchange) for x in records]
@ -37,7 +35,10 @@ def mx_check(
smtp.set_debuglevel(0)
domain = _get_domain_from_email_address(email_address)
mx_records = _get_mx_records(domain)
try:
mx_records = _get_mx_records(domain)
except ValueError:
return False
for mx_record in mx_records:
smtp.connect(mx_record)