January 2019
Beginner to intermediate
776 pages
19h 58m
English
Listing 5.8 shows us the code that finds the domain name from the given email address and verifies it:
#!/usr/bin/env python
# Python Network Programming Cookbook, Second Edition -- Chapter - 5
# This program is optimized for Python 2.7.12 and Python 3.5.2.
# It may run on any other version with/without modifications.
import re
import smtplib
import dns.resolver
import argparse
def mail_checker(fromAddress, toAddress):
regex = '^[a-z0-9][a-z0-9._%+-]{0,63}@[a-z0-9-]+ (\.[a-z0-9-]+)*(\.[a-z]{2,})$'
addressToVerify = str(toAddress)
match = re.match(regex, addressToVerify)
if match == None:
print('Bad Syntax in the address to verify. Re-enter the correct value') raise ValueError('Bad Syntax') splitAddress = addressToVerify.split('@') ...Read now
Unlock full access