Repository navigation
Expand file tree
/
Copy pathsend-certs.py
More file actions
60 lines (50 loc) · 1.73 KB
/
Copy pathsend-certs.py
File metadata and controls
60 lines (50 loc) · 1.73 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import xlrd
import click
import emails
import env
class CertificateMailer(object):
data = {}
workbook = None
def __init__(self, filename):
self.workbook = xlrd.open_workbook(filename)
self.parse_data()
self.send_emails()
def parse_data(self):
sheet = self.workbook.sheet_by_name("presentations")
data = {}
for row_idx in range(1, sheet.nrows):
data[row_idx] = [
sheet.cell(row_idx, 1).value,
sheet.cell(row_idx, 4).value,
]
self.data = data
def send_emails(self):
for key, (name, email) in self.data.items():
subject = "OE Global Conference 2020 - Certificate of Participation"
body = "Dear {},<br /><br />Please find attached your Certificate of Participation.<br /><br />~~ OE Global Team".format(
name
)
msg = emails.html(
subject=subject,
html=body,
mail_from=("OE Global", "conference@oeglobal.org"),
)
msg.attach(
filename="oeglobal-certificate.pdf",
data=open("certs/certificate-{}.pdf".format(key), "rb"),
)
print(subject, body, key)
try:
print(key, name, email)
response = msg.send(to=email, smtp=env.SMTP_SETTINGS)
print(response.status_code)
except:
print("exception", key, name, email)
print(response.status_code)
continue
@click.command()
@click.option("--filename", help="Custom Certificate mailer from xlsx")
def cli(filename):
CertificateMailer(filename)
if __name__ == "__main__":
cli()