import logging from django.core.mail import EmailMultiAlternatives from django.template import Context from django.template.loader import get_template logger = logging.Logger(__name__) class RequestNotifiable(object): MAIL_CATEGORY = 'Request' SLUG_NOTIFICATION = 'notification' SLUG_RESPONSE = 'response' def __init__(self, *args, **kwargs): super(RequestNotifiable, self).__init__(*args, **kwargs) def get_mail_template(self, **kwargs): return None # return MailTemplate.objects.filter(**kwargs).first() def send_request_notification(self, context): """ :param context :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['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__())