def verify_email_recipient(arg_recipient):
if app.debug:
app.logger.debug("verify_email_recipient: email recipient = %s", arg_recipient)
# Inspect email address
result = re.match('^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$', arg_recipient)
if result == None:
if app.debug:
app.logger.debug("verify_email_recipient: Not an email address: %s", arg_recipient)
return False
# Extract domain name from arg_recipient
pieces = arg_recipient.split("@")
if len(pieces) != 2:
if app.debug:
app.logger.debug("verify_email_recipient: Did not split into 2 pieces: %s", arg_recipient)
return False
domain = pieces[1]
if app.debug:
app.logger.debug("verify_email_recipient: email domain = %s", domain)
# Get MX record for target domain
try:
records = dns.resolver.query(domain, 'MX')
mxRecord = str(records[0].exchange)
except:
if app.debug:
app.logger.debug("verify_email_recipient: DNS MX-query exception with %s", domain)
return False
if app.debug:
app.logger.debug("verify_email_recipient: DNS MX record = %s", mxRecord)
return True
#======================================
# Convert epoch time to database format
#======================================
评论列表
文章目录