Last active
June 8, 2019 15:01
-
-
Save stefanocoding/547b7836d73009f3dbb1223cbbe97d07 to your computer and use it in GitHub Desktop.
Useful Python script to know if an email address exists, based on Inti's Medium post https://medium.com/intigriti/abusing-autoresponders-and-email-bounces-9b1995eb53c2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
# Example usage: ./does_email_address_exist.py twitter.com jack | |
import argparse | |
from smtplib import SMTP | |
import dns.resolver | |
parser = argparse.ArgumentParser() | |
parser.add_argument('hostname') | |
parser.add_argument('user') | |
args = parser.parse_args() | |
hostname = args.hostname | |
user = args.user | |
mx_records = dns.resolver.query(hostname, 'MX') | |
server = str(mx_records[0].exchange) | |
with SMTP(server, local_hostname=hostname) as smtp: | |
smtp.helo() | |
smtp.docmd('mail from: <something@something.com>') | |
code, text = smtp.docmd('rcpt to: <'+user+'@'+hostname+'>') | |
if code == 550: | |
print('it does not') | |
else: | |
print('it does exist') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment