Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- import dns.resolver
- import socket
- import smtplib
- import csv
- email_list = ['rbrt.jns90@gmail.com', 'bruno@xuzo.com']
- ##How to write to a CSV
- #dict = [
- # {'emails': 'rbrt.jns90@gmail.com'},
- # {'emails': 'bruno@xuzo.com'},
- # {'emails': 'blah@foo.com'}
- # ]
- #with open('emails.csv', 'w', newline='') as csvfile:
- # fieldnames = ['emails']
- # writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
- # writer.writeheader()
- # for row in dict:
- # writer.writerow(row)
- with open('emails.csv', newline='') as csvfile:
- reader = csv.reader(csvfile, delimiter=',')
- next(reader) # Skip the firstline
- for row in reader:
- row = "".join(row)
- print(row)
- def matcher(row):
- addressToVerify = row
- match = re.match('^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$', addressToVerify)
- if match == None:
- return False
- if match:
- return True
- #address = str(input('Email Address: '))
- if matcher(row) == True: #<- the email from the row above goes here
- regexp = re.search("\@(.*)", row)
- domain = regexp.group(1)
- print("Domain: %s "% domain)
- records = dns.resolver.query(domain, 'MX')
- mxRecord = records[0].exchange
- mxRecord = str(mxRecord)
- # Get local server hostname
- host = socket.gethostname()
- # SMTP lib setup (use debug level for full output)
- server = smtplib.SMTP()
- server.set_debuglevel(0)
- # SMTP Conversation
- server.connect(mxRecord)
- server.helo(host)
- server.mail(row)
- code, message = server.rcpt(str(row))
- server.quit()
- # Assume 250 as Success
- if code == 250:
- print('%s == Success'% row)
- else:
- print('%s == Bad'% row)
- else:
- print("No Match")
- ### CSV file. Open a text editor. Copy and Paste. Save as emails.csv
- emails
- rbrt.jns90@gmail.com
- bruno@xuzo.com
- blah@ymail.com
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement