-
Notifications
You must be signed in to change notification settings - Fork 1
/
mailer.py
31 lines (26 loc) · 937 Bytes
/
mailer.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
import smtplib
def send_emails(emails, message, forecast):
# Connect to the smtp server
server = smtplib.SMTP('smtp.gmail.com', '587')
# Start TLS encryption
server.starttls()
# Login
try:
from_email = input("What's your email?\n")
password = input("What's your password?\n")
server.login(from_email, password)
except smtplib.SMTPAuthenticationError as err:
print('Wrong Authentication!')
exit()
# Send to entire email list
for to_email, name in emails.items():
text = 'Subject: Remember our meeting!\n'
text += 'Hi ' + name + '!\n\n'
text += message + '\n\n'
text += forecast + '\n\n'
text += 'See you there!'
server.sendmail(from_email, to_email, text)
print('The email message was successfully sent to: \n')
for to_email, name in emails.items():
print(to_email + '\n\n')
server.quit()