Skip to content

Instantly share code, notes, and snippets.

@tejastank
Forked from kepsic/check.py
Created August 7, 2022 06:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tejastank/88d38025af20f499f8683876a6518d46 to your computer and use it in GitHub Desktop.
Save tejastank/88d38025af20f499f8683876a6518d46 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
"""
DESCRIPTION
Email checker
INSTALL
sudo apt-get install python3-pip
pip3 install validate_email
pip3 install py3DNS
chmod 755 check.py
./check.py --validate kepsicsassasaa@hot.ee --debug
DEBUG:validate_email:mx1.hot.ee answer: 550 - b'5.1.1 <kepsicsassasaa@hot.ee>: Recipient address rejected: User unknown in relay recipient table'
I'm not sure.
./check.py --mx --validate kepsic@hot.ee --debug
kepsic@hot.ee is valid!
"""
from validate_email import validate_email
import logging
import argparse
def main(args):
if args.debug:
logging.basicConfig()
result = validate_email(args.rcpt,check_mx=args.mx,verify=args.validate,debug=args.debug, smtp_timeout=args.timeout)
if result:
print("%s is valid!" % args.rcpt)
elif result is None:
print("I'm not sure.")
else:
print("%s is invalid!" % args.rcpt)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='email checker')
parser.add_argument('rcpt',help='SMTP rcpt to:' )
parser.add_argument('--mx', action='store_true', default=False,help='MX check' )
parser.add_argument('--validate', action='store_true', default=False,help='Validate check')
parser.add_argument('--smtp_timeout',dest='timeout',type=int, default=10,help='SMTP timeout' )
parser.add_argument('--debug', action='store_true', default=False,help='DEBUG output' )
args = parser.parse_args()
main(args)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment