diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/test_email.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/python/test_email.py b/python/test_email.py new file mode 100644 index 00000000..08509486 --- /dev/null +++ b/python/test_email.py @@ -0,0 +1,37 @@ +# 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() |
