Created
October 3, 2026 10:45
-
-
Save bryanseah234/cab5685633f60e2a0a5007a3280186fb to your computer and use it in GitHub Desktop.
emailverification-code (TypeScript email verification utility with source code under src)
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
| import reimport smtplibimport dns.resolver# Address used for SMTP MAIL FROM command fromAddress = 'corn@bt.com'# Simple Regex for syntax checkingregex = '^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,})$'# Email address to verifyinputAddress = input('Please enter the emailAddress to verify:')addressToVerify = str(inputAddress)# Syntax checkmatch = re.match(regex, addressToVerify)if match == None: print('Bad Syntax') raise ValueError('Bad Syntax')# Get domain for DNS lookupsplitAddress = addressToVerify.split('@')domain = str(splitAddress[1])print('Domain:', domain)# MX record lookuprecords = dns.resolver.query(domain, 'MX')mxRecord = records[0].exchangemxRecord = str(mxRecord)# SMTP lib setup (use debug level for full output)server = smtplib.SMTP()server.set_debuglevel(0)# SMTP Conversationserver.connect(mxRecord)server.helo(server.local_hostname) ### server.local_hostname(Get local server hostname)server.mail(fromAddress)code, message = server.rcpt(str(addressToVerify))server.quit()#print(code)#print(message)# Assume SMTP response 250 is successif code == 250: print('Success')else: print('Bad') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment