Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Useful Python script to know if an email address exists, based on Inti's Medium post
# Example usage: ./ jack
import argparse
from smtplib import SMTP
import dns.resolver
parser = argparse.ArgumentParser()
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.docmd('mail from: <>')
code, text = smtp.docmd('rcpt to: <'+user+'@'+hostname+'>')
if code == 550:
print('it does not')
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.