aboutsummaryrefslogtreecommitdiffstats
path: root/python/mailing_list.py
blob: 40b7e90105c795a6dcb3836c847ed14fe02371d8 (plain)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import smtplib
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from string import Template
from config import gmail_password
from email.utils import make_msgid, formatdate
import os
import csv
import sys

root = "/home/share/serenitas/Fund Raising"

with open(os.path.join(root, sys.argv[1]), "r", encoding='cp1252') as fh:
    csvreader = csv.DictReader(fh)
    mailing_list = [(line["Email"], line["Name"]) for line in csvreader if line["Include?"]=="y"]

#SMTP server
server = smtplib.SMTP('smtp.gmail.com:587')
server.starttls()
server.login("david.weeks@serenitascapital.com", gmail_password)

with open("template-2014-03-11.txt") as fh:
    s_text = Template(fh.read())

with open("template-2014-03-11.html") as fh:
    s_html = Template(fh.read())

attachment_name = 'Serenitas Capital (SCGMF Returns).pdf'
with open(os.path.join(root, "Pitchbook", attachment_name, 'rb'), 'rb') as fh:
    pdf_attach = MIMEApplication(fh.read(), 'pdf')
pdf_attach.add_header('Content-Disposition', 'attachment', filename = attachment_name)

for email, name in mailing_list:
    msg = MIMEMultipart()
    msg['Subject'] = 'Serenitas Credit Gamma Master Fund performance update'
    msg['From'] = 'david.weeks@serenitascapital.com'
    msg['To'] = email
    msg_alternative = MIMEMultipart('alternative')
    msg_alternative.attach(MIMEText(s_text.substitute(name = name),'plain'))
    msg_alternative.attach(MIMEText(s_html.substitute(name = name),'html'))
    msg.attach(msg_alternative)
    msg.attach(pdf_attach)
    server.send_message(msg)
server.quit()