Skip to content

Commit

Permalink
Check emails for validity
Browse files Browse the repository at this point in the history
Checks with reg expressions whether the emails provided could be real
emails containing an @ and a .
Fixes ASPP#13.
  • Loading branch information
ASPP Student committed Sep 3, 2018
1 parent e7a240c commit 66adc07
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions massmail
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,15 @@ def parse_parameter_file(options):

return keywords, email_count

# check the email address for validity

def check_email_validity(addressToVerify):
match = re.match('^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$', addressToVerify)

if match == None:
print('Bad Syntax')
raise ValueError('Bad Syntax')

def create_email_bodies(options, keywords, email_count, body):
# find keywords and substitute with values
# we need to create email_count bodies
Expand All @@ -248,6 +257,7 @@ def add_email_headers(options, msgs):
# we need to add the headers

for emailaddr in msgs:
check_email_validity(str(emailaddr))
msg = msgs[emailaddr]
msg['To'] = str(emailaddr)
msg['From'] = email.header.Header(options['from'])
Expand Down

0 comments on commit 66adc07

Please sign in to comment.