def send_email(template_name, context=None, *args, **kwargs):
context = context or {}<EOL>try:<EOL><INDENT>html = render_to_string(<EOL>context=context,<EOL>template_name='<STR_LIT>'.format(template_name),<EOL>)<EOL><DEDENT>except TemplateDoesNotExist:<EOL><INDENT>html = '<STR_LIT>'<EOL><DEDENT>try:<EOL><INDENT>text = render_to_string(<EOL>context=context,<EOL>template_name='<STR_LIT>'.format(template_name),<EOL>)<EOL><DEDENT>except TemplateDoesNotExist:<EOL><INDENT>text = '<STR_LIT>'<EOL><DEDENT>if not html and not text:<EOL><INDENT>raise NoTemplatesException(template_name)<EOL><DEDENT>return mail.send_mail(<EOL>*args,<EOL>html_message=html,<EOL>message=text,<EOL>**kwargs<EOL>)<EOL>
Send a templated email.

To generate the message used for the email, the method first
searches for an HTML template with the given name
(eg: <template>.html), and renders it with the provided context. The
process is repeated for the plain text message except a 'txt'
extension is used. All other options are forwarded to Django's
``send_mail`` function.

Args:
    template_name:
        The name of the template to use without an extension. The
        extensions ``html`` and ``txt`` are appended to the template
        name and then rendered to provide the email content.
    context:
        A dictionary containing the context to render the message
        with. Defaults to an empty dictionary.

Returns:
    ``1`` if the email is succesfully sent and ``0`` otherwise. The
    return values come from Django's ``send_mail`` function.

Throws:
    NoTemplatesException:
        If neither the HTML nor plain text template can be loaded.