I am trying to run a code with following conditions:
Use MX record lookup and pick the lowest priority (in MX, lowest number is the highest preference)
if MX is not available or not responding, try A record
if None of the above is available, print bad record
I have run the following code:
import dns.resolver
#this reads from a file that has the to domain which is gmail.com
from SMTP_Server.Tests.Envlope import to_domain
records = dns.resolver.resolve(to_domain, 'MX')[0]
print(records)
if records == None:
records = dns.resolver.resolve(to_domain, 'A')
print(records)
else:
raise ValueError("Bad Record")
But I am getting an error even though it does show mx record:
40 alt4.gmail-smtp-in.l.google.com.
raise ValueError("Bad Record")
ValueError: Bad Record
Any assistance is appreciated