Skip to content

Instantly share code, notes, and snippets.

@rjcrystal
Last active November 2, 2017 11:44
Show Gist options
  • Save rjcrystal/5f1bf577105d96f9b4f27969023af285 to your computer and use it in GitHub Desktop.
Save rjcrystal/5f1bf577105d96f9b4f27969023af285 to your computer and use it in GitHub Desktop.
validate emails using flanker
from flanker.addresslib import address
import sys
if(len(sys.argv)>1):
filename="_validated"+sys.argv[1]
opo = open(filename, 'w')
with open(sys.argv[1]) as f:
emails = f.readlines()
for email in emails:
clean_email=email.strip().replace(',','')
stripped_email=address.parse(clean_email,addr_spec_only=True)
if(stripped_email!=None):
op=address.validate_address(str(stripped_email))
if(op != None):
print(stripped_email)
opo.write(str(stripped_email)+ '\n')
opo.close()
else:
print("Please specify a file")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment