Code Monkey home page Code Monkey logo

django-mail-templated's Introduction

Django Mail Templated

Send emails using Django template system

Documentation Status PyPI Package CircleCI Status

This is a tiny wrapper around the standard EmailMessage class and send_mail() function that provides an easy way to create email messages using the Django template system. Just pass template_name and context as the first parameters then use as normal.

Features

  • Built with OOP, KISS and flexibility in mind. Really small and simple, but yet full-featured (I hope).
  • Extends and mimics the built-in Django's EmailMessage and send_mail(). Compatible as much as possible.
  • Fully supports Django template system including template inheritance (thanks to BradWhittington for the note about the problem).
  • Supports any possible template engines and loaders.
  • Supports serialisation (thanks to arjandepooter).
  • Fully covered with tests.
  • Tested with Django 1.4-1.10.
  • Compatible with Python 2 and Python 3.

Documentation

http://django-mail-templated.readthedocs.org

Quick start

Run:

pip install django-mail-templated

And register the app in your settings file:

INSTALLED_APPS = (
    ...
    'mail_templated'
)

Create template:

{% extends "mail_templated/base.tpl" %}

{% block subject %}
Hello {{ user.name }}
{% endblock %}

{% block body %}
{{ user.name }}, this is a plain text message.
{% endblock %}

{% block html %}
{{ user.name }}, this is an <strong>html</strong> message.
{% endblock %}

Send message:

from mail_templated import send_mail
send_mail('email/hello.tpl', {'user': user}, from_email, [user.email])

Advanced usage:

from mail_templated import EmailMessage

message = EmailMessage('email/hello.tpl', {'user': user}, from_email,
                       to=[user.email])
# TODO: Add more useful commands here.
message.send()

More useful info and examples at http://django-mail-templated.readthedocs.org

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.