def resolve_email_domain(domain):
 try:
  answer = dns.resolver.query(domain, 'MX', raise_on_no_answer=False)
 except dns.resolver.NXDOMAIN:
  print ('Error: No such domain', domain)
  return
 if (answer.rrset is not None):
  records = sorted(answer, key=(lambda record: record.preference))
  print ('This domain has', len(records), 'MX records')
  for record in records:
   name = record.exchange.to_text(omit_final_dot=True)
   print ('Priority', record.preference)
   resolve_hostname(name)
 else:
  print 'This domain has no explicit MX records'
  print 'Attempting to resolve it as an A, AAAA, or CNAME'
  resolve_hostname(domain)

def resolve_email_domain ( domain ) : try : answer = dns . resolver . query ( domain , 'MX' , raise_on_no_answer = False ) except dns . resolver . NXDOMAIN : print ( 'Error: No such domain' , domain ) return if ( answer . rrset is not None ) : records = sorted ( answer , key = ( lambda record : record . preference ) ) print ( 'This domain has' , len ( records ) , 'MX records' ) for record in records : name = record . exchange . to_text ( omit_final_dot = True ) print ( 'Priority' , record . preference ) resolve_hostname ( name ) else : print 'This domain has no explicit MX records' print 'Attempting to resolve it as an A, AAAA, or CNAME' resolve_hostname ( domain )
for an email address name@domain find its mail server ip addresses .