diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/mailing_list.py | 45 | ||||
| -rw-r--r-- | python/test_email.py | 37 |
2 files changed, 45 insertions, 37 deletions
diff --git a/python/mailing_list.py b/python/mailing_list.py new file mode 100644 index 00000000..40b7e901 --- /dev/null +++ b/python/mailing_list.py @@ -0,0 +1,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() diff --git a/python/test_email.py b/python/test_email.py deleted file mode 100644 index 08509486..00000000 --- a/python/test_email.py +++ /dev/null @@ -1,37 +0,0 @@ -# Import smtplib for the actual sending function -import smtplib -import pdb - -from email.mime.application import MIMEApplication -from email.mime.multipart import MIMEMultipart -from email.mime.text import MIMEText -from string import Template - -names = ['Alistair', 'Edwin', 'Guillaume'] -emaillist = ["test_{0}@yopmail.com".format(name) for name in names] - -#SMTP server -server = smtplib.SMTP('smtp.gmail.com:587') -server.starttls() -server.login("guillaume.horel@serenitascapital.com","Jdiema;06") - -s = Template("""Hello $name, - -Please find attached our investment letter. - -Best, -David""") - -with open('/home/share/guillaume/Investment Letter/Q4/investment_letter.pdf', 'rb') as fh: - pdf_attach = MIMEApplication(fh.read(), 'pdf') -pdf_attach.add_header('Content-Disposition', 'attachment', filename = 'investment_letter.pdf') - -for i, name in enumerate(names): - msg = MIMEMultipart() - msg['Subject'] = 'Investment update' - msg['From'] = 'guillaume.horel@serenitascapital.com' - msg['To'] = emaillist[i] - msg.attach(pdf_attach) - msg.attach(MIMEText(s.substitute(name = name))) - server.send_message(msg) -server.quit() |
