# -*- coding: utf-8 -*- from django.template.loader import render_to_string from django.core.mail import EmailMessage from .models import Recipient def mail_entry(entry): """Отправить письмо о новом сообщение.""" recipients = Recipient.objects.all().values_list('email', flat=True) if not recipients: raise Exception(u'No recipients; could not send email') template = 'guestbook/mail_entry.txt' subject = u'Новое сообщение' email_body = render_to_string(template, {'entry': entry}) email = EmailMessage(subject=subject, to=recipients, body=email_body) return email.send() def mail_user_notification(user_email, obj): """Отправить пользователю письмо об ответе на его вопрос.""" template = 'guestbook/mail_user_notification.txt' subject = u'Ответ на Ваш вопрос' email_body = render_to_string(template, {'obj': obj}) email = EmailMessage(subject=subject, to=[user_email], body=email_body) return email.send()