Stads_Scraping/mail_handler.py

29 lines
568 B
Python
Raw Normal View History

2017-04-16 19:06:02 +00:00
#!/bin/python3
import sqlite3
import smtplib
import constants
username = constants.EMAIL_USERNAME
password = constants.EMAIL_PASSWORD
conn = sqlite3.connect('mailing_list')
cursor = conn.cursor();
mails = cursor.execute('SELECT email FROM mails')
def handle(new_grades):
fromaddr = username
server = smtplib.SMTP('smtp.gmail.com:587')
server.starttls()
server.login(username, password)
msg = new_grades
for email in mails:
toaddr = email
server.sendmail(fromaddr, toaddr, msg)
server.quit()
conn.close()