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_txt = nfile.read().format(**body_template_values_dict) with open(body_html_template_path) as nfile: self.body_html = nfile.read().format(**body_template_values_dict) # Set txt of email self.set_content(self.body_txt) # Set html alternative self.add_alternative(self.body_html, subtype='html') def set_addresses(self, sender, recipient): self['From'] = sender self['to'] = recipient