Use Django template engine for html email sending.
Package is on the beta version, so bugs may be occured :)
Tested on Django 2.1, but must work on Django 1.8 and higher
Install via pip from Github repository
pip install git+https://github.com/trialine/django-pretty-mails.git
add it to installed apps in django settings.py:
INSTALLED_APPS = (
'django_pretty_mails',
...
)
setup your settings:
PRETTY_MAIL_TYPES = {
'welcome': {
'reply_to_mail': '[email protected]',
'cc': '[email protected]',
'bcc': '[email protected]',
'subject': 'Welcome e-mail',
'subject_prefix': '[Project] ',
'admin_mails': ['[email protected]'],
},
}
send an e-mail:
from django_pretty_mails import send_email
send_email('welcome', context, mails=['[email protected]'])
Place your own design under 'templates/django_pretty_mails/base.html'.
Use Django {% block %} {% endblock %} tag:
{% block page_title %}{% trans "Project | blah blah blah" %}{% endblock page_title %}
{% block greeting %}Hello, customer!{% endblock greeting %}
{% block mail_body %}Content of mail{% endblock mail_body %}
{% block brand_name %}
<a href="{{ SITE_URL }}">
{% trans "Brand name" %}
</a>
{% endblock brand_name %}
{% block logo %}
<a href="{{ SITE_URL }}">
<img src="https://placehold.it/200x90/" title="Project" alt="Project">
</a>
{% endblock logo %}
{% block best_regards %}
<p>{% trans "Best Regards," %}<br>{% trans "Biosan team" %}</p>
{% endblock best_regards %}
{% block socials_btns %}
<a href="#" class="soc-btn fb">{% trans "Facebook" %}</a>
<a href="#" class="soc-btn tw">{% trans "Twitter" %}</a>
{% endblock socials_btns %}
{% block contact_info %}
<p>
{% trans "Email" %}:<strong><a href="mailto:[email protected]">[email protected]</a></strong><br>
{% trans "Web" %}: <strong><a href="{{ SITE_URL }}">example.com</a></strong><br>
</p>
{% endblock contact_info %}
{% block footer %}{% endblock %}
{% block custom_css %}
<style>
.head-wrap {
background-color: #0062a8;
}
.head-wrap .content > table {
background-color: #0062a8;
}
</style>
{% endblock custom_css %}
Place your own plain content with extention: .txt (welcome.txt).
Fallback will be .html template with striptags
processing.
This project is licensed under the MIT License - see the LICENSE.md file for details