{ "info": { "author": "Bradley Whittington", "author_email": "radbrad182@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Framework :: Django", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "==============================\nDjango-Templated-Email\n==============================\n:Info: A Django oriented templated email sending class\n:Author: Bradley Whittington (http://github.com/bradwhittington, http://twitter.com/darb)\n:Tests: .. image:: https://api.travis-ci.org/bradwhittington/django-templated-email.png\n\nOverview\n=================\ndjango-templated-email is oriented towards sending templated emails \nintended for use with transactional mailers (with support for MailchimpSTS, \nand PostageApp), but as a default with a backend class which uses django's \ntemplating system, and django's core.mail functions. The library supports \ntemplate inheritence, adding cc'd and bcc'd recipients, configurable \ntemplate naming and location, with easy switching between backends/providers.\n\nThe send_templated_email method can be thought of as the render_to_response\nshortcut for email.\n\nGetting going - installation\n==============================\n\nInstalling::\n\n pip install django-templated-email\n\nYou can add the following to your settings.py (but it works out the box)::\n\n TEMPLATED_EMAIL_BACKEND = 'templated_email.backends.vanilla_django.TemplateBackend'\n\n # You can use a shortcut version\n TEMPLATED_EMAIL_BACKEND = 'templated_email.backends.vanilla_django'\n\n # You can also use a class directly\n from templated_email.backends.vanilla_django import TemplateBackend\n TEMPLATED_EMAIL_BACKEND = TemplateBackend \n\n\nSending templated emails\n==============================\n\nExample usage using vanilla_django TemplateBackend backend\n\nPython to send mail::\n\n from templated_email import send_templated_mail\n send_templated_mail(\n template_name='welcome',\n from_email='from@example.com',\n recipient_list=['to@example.com'],\n context={\n 'username':request.user.username,\n 'full_name':request.user.get_full_name(),\n 'signup_date':request.user.date_joined\n },\n # Optional:\n # cc=['cc@example.com'],\n # bcc=['bcc@example.com'],\n # headers={'My-Custom-Header':'Custom Value'},\n # template_prefix=\"my_emails/\",\n # template_suffix=\"email\",\n )\n\nIf you would like finer control on sending the email, you can use **get_templated_email**, which will return a django **EmailMessage** object, prepared using the **vanilla_django** backend::\n\n from templated_email import get_templated_mail\n get_templated_mail(\n template_name='welcome',\n from_email='from@example.com',\n to=['to@example.com'],\n context={\n 'username':request.user.username,\n 'full_name':request.user.get_full_name(),\n 'signup_date':request.user.date_joined\n },\n # Optional:\n # cc=['cc@example.com'],\n # bcc=['bcc@example.com'],\n # headers={'My-Custom-Header':'Custom Value'},\n # template_prefix=\"my_emails/\",\n # template_suffix=\"email\",\n )\n\nYou can also **cc** and **bcc** recipients using **cc=['example@example.com']**. Some backends have other parameters you can override, see below.\n\nYour template\n-------------\n\nThe templated_email/ directory needs to be the templates directory.\n\nThe backend will look in *my_app/templates/templated_email/welcome.email* ::\n\n {% block subject %}My subject for {{username}}{% endblock %}\n {% block plain %}\n Hi {{full_name}}, \n\n You just signed up for my website, using:\n username: {{username}}\n join date: {{signup_date}}\n\n Thanks, you rock!\n {% endblock %}\n\nIf you want to include an HTML part to your emails, simply use the 'html' block ::\n\n {% block html %}\n
Hi {{full_name}},
\n\nYou just signed up for my website, using:\n
Thanks, you rock!
\n {% endblock %}\n\nThe plain part can also be calculated from the HTML using `html2text