blob: 08509486bcee5c4b7044bbbbc55c0ad4594b04f8 (
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
|
# 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()
|