diff options
Diffstat (limited to 'Chap16PracRandomChoreEmailer.py')
-rw-r--r-- | Chap16PracRandomChoreEmailer.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/Chap16PracRandomChoreEmailer.py b/Chap16PracRandomChoreEmailer.py new file mode 100644 index 0000000..ff22c7c --- /dev/null +++ b/Chap16PracRandomChoreEmailer.py @@ -0,0 +1,27 @@ +#! python3 + +# Chapter 16 Practice Random Chore Assignment Emailer +# Randomly assigns a list of chores to a list of email addresses +# and emails the chore assignment to the corresponding email address. + +import random +import smtplib + + +def emailChores(rchore, remail): + smtpObj = smtplib.SMTP_SSL('smtp.gmail.com', 465) + smtpObj.ehlo() + smtpObj.login('myemail@address.com', 'mySecretPassword') + body = 'Subject: Your Chore\n\nYour weekly assigned chore is: %s' % rchore + print('Sending chore email to ' + remail + '...') + smtpObj.sendmail('myemail@address.com', remail, body) + smtpObj.quit() + +chores = ['dishes', 'bathroom', 'vaccum', 'trash'] +emails = ['someone@emailaddress.com', 'someone@emailaddress.com'\ + 'someone@emailaddress.com', 'someone@emailaddress.com'] + +for i in range(0, len(emails)): + randomChore = random.choice(chores) + emailChores(randomChore, emails[i]) + chores.remove(randomChore) |