Giter Site home page Giter Site logo

maximzxc / django-db-mailer Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lpgenerator/django-db-mailer

0.0 2.0 0.0 1.84 MB

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

Home Page: https://github.com/LPgenerator/django-db-mailer

License: GNU General Public License v2.0

Python 99.55% JavaScript 0.45%

django-db-mailer's Introduction

What's that

Django module to easily send emails using django templates stored on 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.
That app very simple to install and use on your projects.

Installation:

  1. Using pip:
$ pip install django-db-mailer
  1. Add the dbmail application to INSTALLED_APPS in your settings file (usually settings.py)
  2. Sync database (./manage.py syncdb or ./manage.py migrate)

Usage examples

from dbmail.models import MailTemplate
from dbmail import send_db_mail

# New dbmail template
MailTemplate.objects.create(
    name="Site welcome template",
    subject="Welcome",
    message="Welcome to our site. We are glad to see you.",
    slug="welcome",
    is_html=False,
)

# Send message with created template
send_db_mail(
    # slug was defined on db template
    slug='welcome',

    # recipient can be list, or str separated with comma or simple string
    # '[email protected]' or '[email protected], [email protected]' or
    # ['[email protected]', '[email protected]'] or string Mail group slug
    recipient='[email protected]',

    # All *args params will be accessible on template context
    {
        'username': request.user.username,
        'full_name': request.user.get_full_name(),
        'signup_date': request.user.date_joined
    },

    # You can access to all model fields. For m2m and fk fields, you should use module_name
    MyModel.objects.get(pk=1),

    # Optional kwargs:
    # from_email='[email protected]'
    # cc=['[email protected]'],
    # bcc=['[email protected]'],
    # user=User.objects.get(pk=1),
    #
    # language='ru',
    #
    # attachments=[(filename, content, mimetype)],
    # files=['hello.jpg', 'world.png'],
    # headers={'Custom-Header':'Some value'},
    #
    # queue='default',
    # retry_delay=300,
    # max_retries=3,
    # retry=True,
    # time_limit=30,
    # send_after=60,
    #
    # use_celery=True,
)

Local demo installation

$ sudo apt-get install virtualenvwrapper
$ mkvirtualenv django-db-mailer
$ git clone https://github.com/LPgenerator/django-db-mailer.git
$ cd django-db-mailer
$ python setup.py develop
$ cd demo
$ pip install -r requirements.txt
$ python manage.py syncdb
$ python manage.py migrate
$ python manage.py runserver

Additional information

Revision

For support template revisions, you can install django-reversion. Find information about compatibility with your Django versions here.

Editor

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

Theme

django-db-mailer supported from box django-grappelli skin. Information about compatibility available here.

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.

Translation

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

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:

$ ./manage.py sync_translation_fields --noinput

Postmark backend

Install python-postmark app via pip. Configure your settings:

POSTMARK_API_KEY = ''
POSTMARK_SENDER = '[email protected]'
POSTMARK_TEST_MODE = False
EMAIL_BACKEND = 'postmark.django_backend.EmailBackend'

Older versions

Very simple version of this app, available here. That version do not include celery settings, bcc, api, mail settings, signals, mail groups and model browser.

Note

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

External API usage

$ pip install httpie
$ http -f POST http://127.0.0.1:8000/dbmail/api/ api_key=ZzriUzE slug=welcome [email protected] data='{"name": "Ivan", "age": 20}'
    or
$ curl -X POST http://127.0.0.1:8000/dbmail/api/ --data 'api_key=ZzriUzE&slug=welcome&[email protected]'

Screenshots

/screenshots/template_edit.jpg

/screenshots/templates_changelist.jpg

/screenshots/template_log_changelist.jpg

/screenshots/template_log_view.jpg

/screenshots/group_change.jpg

/screenshots/signal_edit.jpg

/screenshots/signals_changelist.jpg

/screenshots/apps_view.jpg

/screenshots/apps_browse_vars.jpg

/screenshots/smtp_changelist.jpg

/screenshots/apikey_changelist.jpg

/screenshots/bcc_changelist.jpg

Compatibility:

  • Python: 2.6, 2.7
  • Django: 1.4, 1.5, 1.6

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.