From 8de73a32fc73246e2fb966a4cd79ee701767f19f Mon Sep 17 00:00:00 2001 From: Max Yakovenko Date: Wed, 1 Aug 2018 08:22:34 +0300 Subject: [PATCH] add mixin for sending email --- contact_us/mixins.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/contact_us/mixins.py b/contact_us/mixins.py index a451bb2..b571b50 100644 --- a/contact_us/mixins.py +++ b/contact_us/mixins.py @@ -1,7 +1,10 @@ +import logging + from django.core.mail import EmailMultiAlternatives +from django.template import Context from django.template.loader import get_template -from django.utils.translation import ugettext_lazy as _ +logger = logging.Logger(__name__) class RequestNotifiable(object): MAIL_CATEGORY = 'Request' @@ -22,8 +25,17 @@ class RequestNotifiable(object): :param template_path string: :return None: """ + body = get_template('emails/html/contact_email_notification.html') + body_text = get_template('emails/txt/contact_email_notification.txt') email = EmailMultiAlternatives( - context['subject'],'body',context['from_email'], - context['recipients'],context['bcc'] + context['email']['subject'], + body_text.render(context['email']), + context['from_email'], + context['recipients'] ) + email.attach_alternative(body.render(context['email']),'text/html') + try: + email.send() + except Exception as e: + logger.error(e.__str__())