Stads_Scraping/mail_handler.py
2017-04-16 21:06:02 +02:00

29 lines
568 B
Python

#!/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()