Skip to content

vgaicuks/django-pretty-mails

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Django pretty mails

Use Django template engine for html email sending.

Getting Started

Package is on the beta version, so bugs may be occured :)

Prerequisites

Tested on Django 2.1, but must work on Django 1.8 and higher

Installing

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]'])

Templates

Place your own design under 'templates/django_pretty_mails/base.html'.

Overwritable blocks

Use Django {% block %} {% endblock %} tag:

Mail title

{% block page_title %}{% trans "Project | blah blah blah" %}{% endblock page_title %}

Mail greeting

{% block greeting %}Hello, customer!{% endblock greeting %}

Mail body

{% block mail_body %}Content of mail{% endblock mail_body %}

Logo and Brand name

{% 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 %}

best_regards, socials_btns, contact_info and footer

{% 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 %}

custom_css

{% block custom_css %}
    <style>
    .head-wrap {
        background-color: #0062a8;
    }

    .head-wrap .content > table {
        background-color: #0062a8;
    }
    </style>
{% endblock custom_css %}

Plain text templates

Place your own plain content with extention: .txt (welcome.txt).

Fallback will be .html template with striptags processing.

License

This project is licensed under the MIT License - see the LICENSE.md file for details

About

Django templated mails with responsive html design

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published