-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathesncard_ready.py
48 lines (38 loc) · 1.33 KB
/
esncard_ready.py
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
#!/bin/env python3
from django.core.mail import EmailMultiAlternatives
from django.template import Engine, Context
from django.utils.html import strip_tags
from django.conf import settings
from django.core.mail.backends.smtp import EmailBackend as Smtp
settings.configure()
mailer = Smtp(
host='smtp.gmail.com',
port=465,
username='...',
use_ssl=True,
password='...'
)
with open('done-cards.tsv', 'r') as f:
data = [(*d.split('\t'),) for d in f.readlines()]
template = Engine().from_string(open('esncard_ready_template.html').read())
messages = []
for (email, name) in data:
print(email, name)
html_message = template.render(Context({'name': name}))
plain_message = strip_tags(html_message)
mail = EmailMultiAlternatives(
subject='Your ESNcard is ready | ESN VUT Brno',
from_email='Events Manager ESN VUT Brno <[email protected]>',
to=(
# 'President <[email protected]>',
# 'Joe <[email protected]>',
# 'Viceprezident <[email protected]>',
f'{email}',
), # !!!
body=str(plain_message),
connection=mailer,
)
mail.attach_alternative(html_message, 'text/html')
mail.attach_file('./panda-point-open-hours-welcome-week-summer-2022.png')
messages.append(mail)
# mailer.send_messages(messages, )