nopaque/daemon/notify/notification.py

29 lines
1.2 KiB
Python
Raw Normal View History

2020-06-05 12:42:04 +00:00
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)
2020-06-05 12:42:04 +00:00
# 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)
2020-06-05 12:42:04 +00:00
with open(body_html_template_path) as nfile:
self.html = nfile.read().format(**body_template_values_dict)
2020-06-05 12:42:04 +00:00
# Set txt of email
self.set_content(self.body)
2020-06-05 12:42:04 +00:00
# Set html alternative
self.add_alternative(self.html, subtype='html')
2020-06-05 12:42:04 +00:00
def set_addresses(self, sender, recipient):
self['From'] = sender
self['to'] = recipient