Last active
May 4, 2016 17:12
-
-
Save alessandrostein/c83865efbcf7b7f9bdc28d4c8a04461e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Why: Verify email box exists | |
#Author: Bruno da Silva Valenga - <brunodasilvalenga.com.br> | |
#Created: 08/25/2014 | |
#Usage: script.py [email protected] | |
#Install lib DNS: https://github.com/rthalley/dnspython | |
import socket, smtplib, re, sys, dns.resolver | |
addressToVerify = sys.argv[1] | |
match = re.match('^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$', addressToVerify) | |
domain = addressToVerify.split("@")[1] | |
if match == None: | |
print('Bad Syntax') | |
raise ValueError('Bad Syntax') | |
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(addressToVerify) | |
code, message = server.rcpt(str(addressToVerify)) | |
server.quit() | |
# Assume 250 as Success | |
if code == 250: | |
print('Success') | |
else: | |
print('Bad') | |
fiz uns ajustes pra receber a variavel apenas | |
ai voce usa | |
./test-email.py [email protected] | |
ou | |
python test-email.py [email protected] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment