def send_mail(subject, email_template_name, recipients, html_email_template_name,
context, email_from=DEFAULT_FROM_EMAIL):
"""
Sends an email to someone
"""
if 'test' in sys.argv:
return # Don't send mails if we are testing to prevent spam
if context['html']:
body = loader.render_to_string(email_template_name, context)
else:
body = email_template_name
email_message = EmailMultiAlternatives(subject, body, email_from, recipients)
if html_email_template_name is not None:
html_email = loader.render_to_string(html_email_template_name, context)
email_message.attach_alternative(html_email, 'text/html')
email_message.send(fail_silently=True)
评论列表
文章目录