diff options
| -rw-r--r-- | python/mailing_list.py | 86 |
1 files changed, 46 insertions, 40 deletions
diff --git a/python/mailing_list.py b/python/mailing_list.py index b55fbfbd..b6017345 100644 --- a/python/mailing_list.py +++ b/python/mailing_list.py @@ -11,49 +11,55 @@ import xlrd root = "/home/share/serenitas/Fund Raising" -book = xlrd.open_workbook(os.path.join(root, sys.argv[1])) -sheet = book.sheet_by_name("Distribution List") -emails, names, include, firm = sheet.col(4), sheet.col(5), sheet.col(6), sheet.col(2) -mailing_list = [(emails[i].value, names[i].value, firm[i].value) for i, y in enumerate(include[3:], 3) if y.value.lower()=="x"] +def get_mailinglist(name): + book = xlrd.open_workbook(os.path.join(root, name)) + sheet = book.sheet_by_name("Distribution List") + emails, names, include, firm = sheet.col(4), sheet.col(5), sheet.col(6), sheet.col(2) + mailing_list = [(emails[i].value, names[i].value, firm[i].value) \ + for i, y in enumerate(include[3:], 3) if y.value.lower()=="x"] + return mailing_list -#SMTP server -server = smtplib.SMTP('smtp.gmail.com:587') -server.starttls() -server.login(gmail_login, gmail_password) -with open("templates/template-2015-03-16.txt") as fh: - s_text = Template(fh.read()) +if __name__=="__main__": + #SMTP server + server = smtplib.SMTP('smtp.gmail.com:587') + server.starttls() + server.login(gmail_login, gmail_password) -with open("templates/template-2015-03-16.html") as fh: - s_html = Template(fh.read()) + with open("templates/template-{0}.txt".format(sys.argv[2])) as fh: + s_text = Template(fh.read()) -attachment_name = 'Serenitas Capital (SCGMF Returns).pdf' -with open(os.path.join(root, "Pitchbook", attachment_name), 'rb') as fh: - pdf_attach1 = MIMEApplication(fh.read(), 'pdf') -pdf_attach1.add_header('Content-Disposition', 'attachment', filename = attachment_name) + with open("templates/template-{0}.html".format(sys.argv[2])) as fh: + s_html = Template(fh.read()) -# attachment_name = 'Serenitas Credit Gamma Master Fund - Investor Letter 4Q2014.pdf' -# with open(os.path.join(root, "InvestorLetters", attachment_name), 'rb') as fh: -# pdf_attach2 = MIMEApplication(fh.read(), 'pdf') -# pdf_attach2.add_header('Content-Disposition', 'attachment', filename = attachment_name) + attachment_name = 'Serenitas Capital (SCGMF Returns).pdf' + with open(os.path.join(root, "Pitchbook", attachment_name), 'rb') as fh: + pdf_attach1 = MIMEApplication(fh.read(), 'pdf') + pdf_attach1.add_header('Content-Disposition', 'attachment', filename = attachment_name) -for email, name, firm in mailing_list: - print(email, name, firm) - msg = MIMEMultipart() - msg['Subject'] = 'Serenitas Credit Gamma Master Fund performance update' - msg['From'] = "David Weeks <{0}>".format(gmail_login) - msg['Bcc'] = "emailtosalesforce@1a7zwrpdeh1r43lchk09sz5k0dwx6iflkdijx744qy37umu3ad.o-hlm5eac.na17.le.salesforce.com" - msg['To'] = email - msg['List-Unsubscribe'] = "<mailto:info+unsubscribe@serenitascapital.com>" - msg_alternative = MIMEMultipart('alternative') - if name: - name = " " + name - # msg_alternative.attach(MIMEText(s_text.substitute(name = name, firm_name=firm.rstrip()), 'plain')) - # msg_alternative.attach(MIMEText(s_html.substitute(name = name, firm_name=firm.rstrip()), 'html')) - 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_attach1) - # msg.attach(pdf_attach2) - server.send_message(msg) -server.quit() + attachment_name = 'Serenitas Credit Gamma Master Fund - Investor Letter 1Q2015.pdf' + with open(os.path.join(root, "InvestorLetters", attachment_name), 'rb') as fh: + pdf_attach2 = MIMEApplication(fh.read(), 'pdf') + pdf_attach2.add_header('Content-Disposition', 'attachment', filename = attachment_name) + + mailing_list = get_mailinglist(sys.argv[1]) + for email, name, firm in mailing_list: + print(email, name, firm) + msg = MIMEMultipart() + msg['Subject'] = 'Serenitas Credit Gamma Master Fund performance update' + msg['From'] = "David Weeks <{0}>".format(gmail_login) + msg['Bcc'] = "emailtosalesforce@1a7zwrpdeh1r43lchk09sz5k0dwx6iflkdijx744qy37umu3ad.o-hlm5eac.na17.le.salesforce.com" + msg['To'] = email + msg['List-Unsubscribe'] = "<mailto:info+unsubscribe@serenitascapital.com>" + msg_alternative = MIMEMultipart('alternative') + if name: + name = " " + name + # msg_alternative.attach(MIMEText(s_text.substitute(name = name, firm_name=firm.rstrip()), 'plain')) + # msg_alternative.attach(MIMEText(s_html.substitute(name = name, firm_name=firm.rstrip()), 'html')) + 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_attach1) + msg.attach(pdf_attach2) + server.send_message(msg) + server.quit() |
