Skip to content

Instantly share code, notes, and snippets.

@stefanocoding
Last active June 8, 2019 15:01
Show Gist options
  • Save stefanocoding/547b7836d73009f3dbb1223cbbe97d07 to your computer and use it in GitHub Desktop.
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
#!/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: <[email protected]>')
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