- Version
0.1
- Tests
- Example
Fancy mail is a Django app to help managing your templated emails. The aim of this app is to be simple and to reuse all the stuff that Django gives us, like the email classes that works perfect (Thank you Django). There are alternatives like Django templated mail. But this app has many options, like backends, template renderers...
Fancy mail is more simple, you say where is the html template, what are the variables to use (context) and the text template (this is optional) and we are done!
Why use fancy mail?
In two words: is simple!
What comes in the box?
You can use Fancy mail in two forms like the Django email. You can use the class of FancyMail
directly or you can use shortcuts
- Django 1.4.*
- TODO: Test with 1.3.*
pip install git+git://github.com/slok/django-fancymail.git
Fancy mail uses de Dajngo renderer for the templates so by default this uses the template loader.
Add to the template loader in our settings TEMPLATE_LOADERS
var this:
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
Now we need to add the directory where our templates are. For example in the root directory of our app we will place a directory called email_templates
with this estructure:
./email_templates/
|
`-- email
|-- base.html
|-- base.txt
|-- welcome.html
`-- welcome.txt
So we add in the settings TEMPLATE_DIRS
this (in production add full path not relative):
'email_templates/'
We are ready to use it!
Using the class directoly (this has more options, the same options that the Django documentation explains for EmailMultiAlternatives and EmailMessage)
First import:
from fancymail.mail import FancyMail
then you need to create an instance of FancyMail with the needed data:
msg = FancyMail(subject="This is a test email",
from_email="test1@djangofancymail.org",
to=("test2@djangofancymail.org",))
Then you need to load the templates:
msg.load_template("email/welcome.html", {'user': "slok"}, "email/welcome.txt")
OR set in the instance (when send the templates will be rendered) if you prefer:
msg.html_template = "email/welcome.html"
msg.context = {'user': "slok"}
msg.text_template = "email/welcome.txt"
Send the email!:
msg.send()
simple and easy :)
Even simpler!:
send_mail("This is a test email", "email/welcome.html", {'user': "slok"},
"test1@djangofancymail.org", ("test2@djangofancymail.org",),
"email/welcome.txt")
- Documentation
- more shortcuts
Xabier (slok) Larrakoetxea <slok69 [at] gmail.com>
3 clause/New BSD license OpenSource, Wikipedia,