Skip to main content

Django module to easily send emails using django templates stored in a database.

Project description

Django-Db-Mailer
================

.. image:: https://api.travis-ci.org/LPgenerator/django-db-mailer.png?branch=development
:alt: Build Status
:target: https://travis-ci.org/LPgenerator/django-db-mailer
.. image:: https://landscape.io/github/LPgenerator/django-db-mailer/master/landscape.svg
:target: https://landscape.io/github/LPgenerator/django-db-mailer/master
:alt: Code Health
.. image:: https://api.codacy.com/project/badge/grade/ad1442e15215494499ed08b80d4c41c5
:target: https://www.codacy.com/app/gotlium/django-db-mailer
:alt: Codacy
.. image:: https://img.shields.io/badge/python-2.7,3.4+,pypy,pypy3-blue.svg
:alt: Python 2.7, 3.4+, pypy, pypy3
:target: https://pypi.python.org/pypi/django-db-mailer/
.. image:: https://img.shields.io/pypi/v/django-db-mailer.svg
:alt: Current version on PyPi
:target: https://pypi.python.org/pypi/django-db-mailer/
.. image:: https://readthedocs.org/projects/django-db-mailer/badge/?version=latest
:target: http://django-db-mailer.readthedocs.org/
:alt: Documentation Status
.. image:: https://img.shields.io/badge/license-GPLv2-green.svg
:target: https://pypi.python.org/pypi/django-db-mailer/
:alt: License


Documentation available at `Read the Docs <http://django-db-mailer.readthedocs.org/>`_.


What's that
-----------
| Django module to easily send emails/push/sms/tts using django templates stored in a database.
| From box you can use it with django-celery for send background messages.
| Also you have opportunity to create reports from logs by mail categories and slug.
| Groups with Recipients and send by model signal also available by default.
| Can be used without any depends from programming language as a external service.
| That app very simple to install and use on your projects.


Installation
------------

1. Using pip:

.. code-block:: bash

You can't use 'macro parameter character #' in math mode git clone --depth 1 -b master https://github.com/LPgenerator/django-db-mailer.git db-mailer
cddbmailer docker build -t dbmail .
dockerrunitdp8000:8000namedbmaildbmail docker exec -i -t dbmail /bin/bash
cd/mailer/Vagrant..codeblock::bash git clone --depth 1 -b master https://github.com/LPgenerator/django-db-mailer.git db-mailer
cddbmailer vagrant up --provider virtualbox
vagrantssh cd /mailer/


**OS X/Linux**


.. code-block:: bash

sudoaptgetinstallyvirtualenvwrapperredisservergitpythondevlibxml2devlibxsltdevzlib1gdev||brewinstallpyenvvirtualenvwrapperredisgit source /usr/share/virtualenvwrapper/virtualenvwrapper.sh || source /usr/local/bin/virtualenvwrapper.sh
mkvirtualenvdbmailer workon db-mailer
gitclonedepth1https://github.com/LPgenerator/djangodbmailer.gitdbmailer cd db-mailer
pythonsetup.pydevelop cd demo
pipinstallrrequirements.txt python manage.py migrate --noinput
pythonmanage.pycreatesuperuserusernameadminemailadmin@local.host redis-server >& /dev/null &
Misplaced & python manage.py celeryd -Q default >& /dev/null &


Open Shell:

.. code-block:: bash

pythonmanage.pyshellplusprintsqlCreatenewtemplate:..codeblock::pythonfromdbmail.modelsimportMailTemplatefromdbmailimportsenddbmailMailTemplate.objects.create(name="Sitewelcometemplate",subject="Welcome",message="Welcometooursite.Wearegladtoseeyou.",slug="welcome",ishtml=False,)Trytosendtestemailwithcreatedtemplate(withoutcelery):..codeblock::pythonsenddbmail(welcome,user@example.com,usecelery=False)Sendemailusingcelery:..codeblock::pythonsenddbmail(welcome,user@example.com)Checkmaillogs:..codeblock::pythonfrompprintimportpprintfromdjango.forms.modelsimportmodeltodictfromdbmail.modelsimportMailLogpprint([modeltodict(obj)forobjinMailLog.objects.all()])Openappinbrowser(loginandpasswordisadmin/admin):..codeblock::bash xdg-open http://127.0.0.1:8000/admin/dbmail/ >& /dev/null || open http://127.0.0.1:8000/admin/dbmail/ >& /dev/null


Additional information
----------------------

**Revision**

For support template reversion, you can install ``django-reversion``.
Find information about compatibility with your Django versions `here <http://django-reversion.readthedocs.org/en/latest/django-versions.html>`_.

**Editor**

To enable editor, you may install and configure ``django-tinymce`` or ``django-ckeditor`` app.

**Theme**

``django-db-mailer`` supported from box ``django-grappelli`` and ``django-suit`` skin. Information about compatibility available `here <https://pypi.python.org/pypi/django-grappelli/2.5.3>`_.

**Queue**

Install and configure ``django-celery`` for background message sending with priorities. You can find celery settings examples on demo project.
We recommended to use ``django-celery-mon`` with ``django-celery`` for monitoring celery and supervisor processes.

**Premailer**

For turns CSS blocks into style attributes, you can install ``premailer`` from PyPi.

**Translation**

For use different language on your mail templates, install ``django-modeltranslation`` or ``grappelli-modeltranslation``.
Add into settings.py:

.. code-block:: python

MODELTRANSLATION_DEFAULT_LANGUAGE = 'en'
MODELTRANSLATION_LANGUAGES = ('ru', 'en')
MODELTRANSLATION_TRANSLATION_FILES = (
'dbmail.translation',
)
INSTALLED_APPS = ('modeltranslation',) + INSTALLED_APPS
# INSTALLED_APPS = ('grappelli', 'grappelli_modeltranslation', 'modeltranslation',) + INSTALLED_APPS


Update dbmail fields:

.. code-block:: bash

You can't use 'macro parameter character #' in math mode pip install httpagentparser django-ipware geoip2

For track information about user, or about mail is read, you must be enable logging, and enable tracking on settings.

If you use Django 1.8, you should install `geoip` package instead of `geoip2`.

**MJML**

MJML is a markup language designed to reduce the pain of coding a responsive email.
Install ``django-mjml`` app via pip and ``mjml`` via npm. And configure your settings:

.. code-block:: python

INSTALLED_APPS = (
...,
'mjml',
)


**Older versions**

Very simple version of this app, available `here <https://github.com/LPgenerator/django-db-mailer/tree/1.0>`_.
That version do not include celery settings, bcc, api, mail settings, signals, mail groups and model browser.


**Notes**

All app features available only with ``django-celery`` and with ``Redis``.

.. code-block:: bash

pipinstallredishiredisdjangoceleryExternalAPIusage..codeblock::pythonfromdbmail.modelsimportApiKeyApiKey.objects.create(name=Test,apikey=ZzriUzE)..codeblock::bash pip install httpie
httpfPOSThttp://127.0.0.1:8000/dbmail/api/apikey=ZzriUzEslug=welcomerecipient=root@local.hostdata="name":"Ivan","age":20or apt-get install curl || brew install curl
$ curl -X POST http://127.0.0.1:8000/dbmail/api/ --data 'api_key=ZzriUzE&slug=welcome&recipient=root@local.host&backend=mail'

*API bandwidth is 1k+ rps on i7 2.3GHz*


Responsive transactional HTML email templates
---------------------------------------------
Fixtures with Base transactional HTML email templates was added into dbmail fixtures.
This templates was optimized for desktop clients, web clients, mobile clients, various devices, various providers.
Thanks for Mailgun Team. You can use it as default basic templates on your project.

.. code-block:: bash

python manage.py load_dbmail_base_templates



Publications
------------
* `Установка и использование с примерами на русском <http://habrahabr.ru/post/253445/>`_.
* `Completely installation and usage with examples. Translated by Google <http://translate.google.com/translate?hl=en&sl=ru&tl=en&u=http://habrahabr.ru/post/253445/>`_.


Screenshots
-----------

.. image:: /screenshots/template_edit.jpg
.. image:: /screenshots/templates_changelist.jpg
.. image:: /screenshots/template_log_changelist.jpg
.. image:: /screenshots/template_log_view.jpg
.. image:: /screenshots/group_change.jpg
.. image:: /screenshots/signal_edit.jpg
.. image:: /screenshots/signals_changelist.jpg
.. image:: /screenshots/apps_view.jpg
.. image:: /screenshots/apps_browse_vars.jpg
.. image:: /screenshots/smtp_changelist.jpg
.. image:: /screenshots/apikey_changelist.jpg
.. image:: /screenshots/bcc_changelist.jpg
.. image:: /screenshots/template_compare.jpg
.. image:: /screenshots/tracking_edit.jpg
.. image:: /screenshots/base_template_changelist.jpg
.. image:: /screenshots/subscriptions_change.jpg
.. image:: /screenshots/subscriptions_changelist.jpg


Compatibility
-------------
* Python: 2.7, pypy2.7, 3.4, 3.5, 3.6, 3.7, pypy3.5
* Django: 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 1.10, 1.11, 2.0, 2.1

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page