-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
45 lines (36 loc) · 1.4 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import config
import createConnections
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
def main():
for participant in createConnections.participants:
# format email
body = "SHHHH, you have " + participant.secretSanta + '''!
Please remember to keep gifts $150 max
Looking forward to seeing everyone!'''
subject = "Secret Santa"
msg = MIMEMultipart()
msg['To'] = participant.email
msg['From'] = config.gmail_user
msg['Subject'] = subject
msg.attach(MIMEText(body,'plain'))
message = msg.as_string()
try:
# send emails
server = smtplib.SMTP(config.mailFromServer)
server.starttls()
server.login(config.gmail_user, config.gmail_password)
server.sendmail(config.gmail_user, participant.email, message)
server.quit()
# write connections to log incase of email error, or people forget
f = open('log.txt', 'a')
f.write(participant.name + " has " + participant.secretSanta + "\n")
f.close()
# console confirmation
print("Email Sent!")
except:
# print sending error to console
print("Email Sending Error:", participant.email)
if __name__ == "__main__":
main()