# Server normaly return an normalize email address
forwordinmsg.split(''):
ifvalidate_email(word):
returnTrue
smtp.mail('')
status,msg=smtp.rcpt(mail)
ifstatus>=400andstatus<500:
logging.debug('SMTP server return temporary error (code=%s) : %s',status,msg)
returnnotoptions.refuseontemporaryerror
elifstatus!=250:
returnFalse
returnTrue
exceptsmtplib.SMTPServerDisconnected:
# Server not permits verify user
mx_refuse_check_mail.append(mx_host)
returnif_not_permit
exceptsmtplib.SMTPConnectError:
returnFalse
defmass_validate_email(mail,simple=False):
mail=clean_mail(mail)
ifnotvalidate_email(mail):
return
elifsimple:
returnTrue
elifoptions.checkmx:
returncheck_mx(mail)
else:
returnTrue
if__name__=='__main__':
fromoptparseimportOptionParser
parser=OptionParser()
# options
parser.add_option(
'-v',
'--verbose',
action="store_true",
dest="verbose",
help='Enable verbose mode'
)
parser.add_option(
'-d',
'--debug',
action="store_true",
dest="debug",
help='Enable debug mode'
)
parser.add_option(
'-p',
'--progress',
action='store_true',
dest='progress',
help='Enable progress bar',
default=False
)
parser.add_option(
'-D',
'--debug-smtp',
action="store_true",
dest="debugsmtp",
help='Enabled SMTP exchange debuging'
)
parser.add_option(
'-m',
'--mx',
action="store_true",
dest="checkmx",
help='Enable MX check'
)
parser.add_option(
'-V',
'--verify',
action="store_true",
dest="verifyaddress",
help="Enable email address verification on MX server. If this option is enabled, MX check is also automatically enabled."
)
parser.add_option(
'--use-smtp-vrfy',
action="store_true",
dest="usesmtpvrfy",
help="When MX check is enabled, enable the SMPT VRFY command usage"
)
parser.add_option(
'--accept-mail-if-not-permit',
action="store_false",
dest="refusemailifnotpermit",
help="When MX check is enabled, accept email address even if MX server refuse the SMTP connection (after HELO command)"
)
parser.add_option(
'--accept-on-temporary-error',
action="store_false",
dest="refuseontemporaryerror",
help="When MX check is enabled, accept email address even if MX server return a temporary error (after trying to send an email to the checked address)"
)
parser.add_option(
'-f',
'--from-file',
action="store",
type='string',
dest="fromfile",
help="Read emails addresses to validate from from"