Пример #1
0
def send_template(subject="", html=None, text=None, rcpt=[], sender=None, context_instance=None, fail_silently=True, connection=None):
    from thistle import render_to_string, Context

    if not context_instance:
        context_instance = Context()

    if text:
        body_text = render_to_string(text, context_instance)
    else:
        body_text = ""
    msg = EmailMultiAlternatives(subject, body_text, sender, rcpt)

    if html:
        body_html = render_to_string(html, context_instance)
        msg.attach_alternative(body_html, 'text/html')

    if not connection:
        connection = SMTPClient()
    connection.send_message(msg)