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