aboutsummaryrefslogtreecommitdiffstats
path: root/mailing.py
diff options
context:
space:
mode:
authorGuillaume Horel <guillaume.horel@gmail.com>2015-04-05 21:15:29 -0400
committerGuillaume Horel <guillaume.horel@gmail.com>2015-04-05 21:15:29 -0400
commit81807b2a4471620c4ddd27c0a61f87b86f3136a4 (patch)
tree544a69d15103ff7a458234cbc09808772ad449a8 /mailing.py
parent8a792206d3e687fd91f69e275a46a881b03964bc (diff)
downloadwedding-website-81807b2a4471620c4ddd27c0a61f87b86f3136a4.tar.gz
basic mailing tool
Diffstat (limited to 'mailing.py')
-rw-r--r--mailing.py33
1 files changed, 33 insertions, 0 deletions
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()