As we all know (or should), you can use Django's template system to render email bodies:
def email(email, subject, template, context):
from django.core.mail import send_mail
from django.template import loader, Context
send_mail(subject, loader.get_template(template).render(Context(context)), '[email protected]', [email,])
This has one flaw in my mind: to edit the subject and content of an email, you have to edit both the view and the template. While I can justify giving admin users access to the templates, I'm not giving them access to the raw python!
What would be really cool is if you could specify blocks in the email and pull them out separately when you send the email:
{% block subject %}This is my subject{% endblock %}
{% block plaintext %}My body{% endblock%}
{% block html %}My HTML body{% endblock%}
But how would you do that? How would you go about rendering just one block at a time?