From 81807b2a4471620c4ddd27c0a61f87b86f3136a4 Mon Sep 17 00:00:00 2001 From: Guillaume Horel Date: Sun, 5 Apr 2015 21:15:29 -0400 Subject: basic mailing tool --- mailing.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 mailing.py diff --git a/mailing.py b/mailing.py new file mode 100644 index 0000000..40e0b39 --- /dev/null +++ b/mailing.py @@ -0,0 +1,33 @@ +import smtplib +from email.mime.text import MIMEText +from email.mime.multipart import MIMEMultipart +from string import Template +from config import gmail_login, gmail_password + +#SMTP server +server = smtplib.SMTP('smtp.gmail.com:587') +server.starttls() +server.login(gmail_login, gmail_password) + +with open("templates/email_2015-04-05.txt") as fh: + s_text = Template(fh.read()) + +with open("templates/email_2015-04-05.html") as fh: + s_html = Template(fh.read()) + +with open("test.csv") as fh: + mailing_list = [line.strip().split(",") for line in fh] + +for email, name, username in mailing_list: + print(email, name, username) + msg = MIMEMultipart('alternative') + msg['Subject'] = 'Wedding Invitation' + msg['From'] = "Iva and Guillaume <{0}>".format(gmail_login) + msg['To'] = email + + part1 = MIMEText(s_text.substitute(name=name, username=username), 'plain') + part2 = MIMEText(s_html.substitute(name=name, username=username), 'html') + msg.attach(part1) + msg.attach(part2) + server.send_message(msg) +server.quit() -- cgit v1.2.3-70-g09d2