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.

Revisions

  1. stefanocoding revised this gist Feb 23, 2019. No changes.
  2. stefanocoding revised this gist Feb 23, 2019. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions does_email_address_exist.py
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    #!/usr/bin/python3
    # Example usage: ./does_email_address_exist.py twitter.com jack
    import argparse
    from smtplib import SMTP
    import dns.resolver
  3. stefanocoding created this gist Feb 23, 2019.
    24 changes: 24 additions & 0 deletions does_email_address_exist.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    #!/usr/bin/python3
    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')