Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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: <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
You can’t perform that action at this time.