add mixin for sending email

remotes/origin/HEAD
Max Yakovenko 8 years ago
parent 5479dc57dd
commit 8de73a32fc
  1. 18
      contact_us/mixins.py

@ -1,7 +1,10 @@
import logging
from django.core.mail import EmailMultiAlternatives from django.core.mail import EmailMultiAlternatives
from django.template import Context
from django.template.loader import get_template from django.template.loader import get_template
from django.utils.translation import ugettext_lazy as _
logger = logging.Logger(__name__)
class RequestNotifiable(object): class RequestNotifiable(object):
MAIL_CATEGORY = 'Request' MAIL_CATEGORY = 'Request'
@ -22,8 +25,17 @@ class RequestNotifiable(object):
:param template_path string: :param template_path string:
:return None: :return None:
""" """
body = get_template('emails/html/contact_email_notification.html')
body_text = get_template('emails/txt/contact_email_notification.txt')
email = EmailMultiAlternatives( email = EmailMultiAlternatives(
context['subject'],'body',context['from_email'], context['email']['subject'],
context['recipients'],context['bcc'] 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__())

Loading…
Cancel
Save