Jump to content
Fi8sVrs

email verifier .py

Recommended Posts

  • Active Members
Posted

Yet Another Email Verifier 1.0

Verify emails by checking the "RCPT TO" return code from the SMTP server.

Hints:

  • The output is separated by commas, so you can easily import it to another application (e.g. MS Excel).
  • Create an address list by using the Smashing Email eXtractor!
  • Failed checks are added at the bottom (! <domain>)

Requirements:

Usage:

yaev.py <file>

file: absolute path to email-address list

Example:

[B]$ cat addresses.txt[/B]
[B]...[/B]
wolfgang.schaeuble@wk.bundestag.de
gm.schulz@gmail.com
jan.sipocz@gmail.com
brigitte.kopinits@gmail.com
r.buchmann@amag.at
annimarie.schaffer@gmail.com
iggy.popovic@gmail.com
erich.gabis@gmail.com
Kovacs.maria4@gmail.com
andreas.schimon@gmail.com
barbarajungreithmair@gmail.com
michael.gabis@gmail.com
[B]$ ./yaev.py addresses.txt > checked_emails.txt
$ cat checked_emails.txt
...[/B]
wolfgang.schaeuble@wk.bundestag.de,mail1.dbtg.de,554,5.7.1 Service unavailable; Client host [83.187.177.131] blocked using zen.spamhaus.org; http://www.spamhaus.org/query/bl?ip=83.187.177.131
gm.schulz@gmail.com,alt2.gmail-smtp-in.l.google.com,250,2.1.5 OK 6si6034pxi.95
jan.sipocz@gmail.com,alt2.gmail-smtp-in.l.google.com,250,2.1.5 OK 13si2013478pxi.35
brigitte.kopinits@gmail.com,alt2.gmail-smtp-in.l.google.com,250,2.1.5 OK 27si2008921pxi.56
r.buchmann@amag.at,srxx0055.amag.at,503,5.0.0 Need MAIL before RCPT
annimarie.schaffer@gmail.com,alt2.gmail-smtp-in.l.google.com,250,2.1.5 OK 35si2021257pxi.2
iggy.popovic@gmail.com,alt2.gmail-smtp-in.l.google.com,250,2.1.5 OK 37si2019611pxi.5
erich.gabis@gmail.com,alt2.gmail-smtp-in.l.google.com,250,2.1.5 OK 2si2010789pxi.52
Kovacs.maria4@gmail.com,alt2.gmail-smtp-in.l.google.com,250,2.1.5 OK 42si2017013pxi.17
andreas.schimon@gmail.com,alt2.gmail-smtp-in.l.google.com,250,2.1.5 OK 9si2018016pxi.13
barbarajungreithmair@gmail.com,alt2.gmail-smtp-in.l.google.com,250,2.1.5 OK 40si2003494pxi.87
michael.gabis@gmail.com,alt2.gmail-smtp-in.l.google.com,250,2.1.5 OK 37si2019846pxi.5
!gmx.de

Code:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# yaev.py
#
# Version: 1.0
#
# Copyright (C) 2009 novacane novacane[at]dandies[dot]org
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# DO NOT FORGET TO INSTALL DNSPYTHON - http://www.dnspython.org/
#
# For more information visit:
# http://dandies.org/files/41b1d9240cf1df328f4e63d087769440-44.html
#

import os
import sys
import smtplib
import dns.resolver

def main(path_to_src_file):

""" Get SMTP return code

Verify emails by checking the "RCPT TO" return code from the SMTP server.
NOTE: dropped vrfy command because provider disabled it to prevent attacks

"""

failed_domains = []

try:
# Open the Source-File.
file_emails = open(path_to_src_file)
except IOError:
print "Error reading file!"
print "!> " + path_to_src_file
sys.exit(1)

# Loop through addresses. Each line represents an email-address.
for line in file_emails:
# Remove Linefeed.
line = line.replace("\n", "")
# The actual domain.
domain = line.split("@")[1]

# Do nothing if domain is already in the failed_domain list.
if not domain in failed_domains:
try:
# Make a MX DNS query.
answers = dns.resolver.query(domain, "MX")
# OR: mx = str(answers[1].exchange)[:-1]
for rdata in answers:
# Remove the dot from rdata.exchange.
mx = str(rdata.exchange)[:-1]
try:
# Connect to SMTP server.
smtp = smtplib.SMTP(mx)
# Polite people say hello first.
smtp.docmd("HELO microsoft.com")
# Indicates who is sending the mail.
smtp.docmd("MAIL FROM:", "<asdf@microsoft.com>")
# Indicates who is recieving the mail.
rcpt = smtp.docmd("RCPT TO:", "<" + line + ">")
# Print output.
print line + "," + mx + "," + \
str(rcpt[0]) + "," + str(rcpt[1])
# Close SMTP connection.
smtp.quit()
except smtplib.SMTPServerDisconnected:
# Add domain to list.
failed_domains.append(domain)
# Use only the first server-address.
break

# Raise exception if DNS query failed.
except dns.resolver.NXDOMAIN:
# Add domain to list.
failed_domains.append(domain)

# Close the Source-File.
file_emails.close()

# Output failed domains.
if failed_domains:
for item in failed_domains: print "!" + item

if __name__ == '__main__':
if len(sys.argv) != 2:
print "\n\t[*] yet another email verifier 1.0 [*]"
print "\n\tUsage: yaev.py <file>"
sys.exit(2)

main(sys.argv[1])

Dounload source

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...