diyca_web_utilities.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:diyca 作者: texadactyl 项目源码 文件源码
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
#======================================
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号