mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-12-26 19:34:19 +00:00
29 lines
1.2 KiB
Python
29 lines
1.2 KiB
Python
from email.message import EmailMessage
|
|
|
|
|
|
class Notification(EmailMessage):
|
|
"""docstring for Email."""
|
|
|
|
def set_notification_content(self,
|
|
subject_template,
|
|
subject_template_values_dict,
|
|
body_txt_template_path,
|
|
body_html_template_path,
|
|
body_template_values_dict):
|
|
# Create subject with subject_template_values_dict
|
|
self['subject'] = subject_template.format(
|
|
**subject_template_values_dict)
|
|
# Open template files and insert values from body_template_values_dict
|
|
with open(body_txt_template_path) as nfile:
|
|
self.body = nfile.read().format(**body_template_values_dict)
|
|
with open(body_html_template_path) as nfile:
|
|
self.html = nfile.read().format(**body_template_values_dict)
|
|
# Set txt of email
|
|
self.set_content(self.body)
|
|
# Set html alternative
|
|
self.add_alternative(self.html, subtype='html')
|
|
|
|
def set_addresses(self, sender, recipient):
|
|
self['From'] = sender
|
|
self['to'] = recipient
|