Skip to main content

Django mail mixins and utilities

Project description

=================
django-mail-utils
=================

Django mail mixins and utilities.

Contents
========
TemplateMixin
-------------
The mixin allows to create email body from a template (any text file).

| ``template_name`` - a path to a template in one of TEMPLATE_DIRs.
| ``template_context`` - a dictionary of variables passed to a template.

Both ``template_name`` and ``template_context`` can be set in inherited classes or
updated from constructor parameters.

Also you can pass the template string like the constructor's ``body`` parameter.
Then it will be used to render the real email's body.

EnvelopeMixin
-------------
The mixin allows to predefine email parameters ``subject``, ``from_email``, ``to``,
``cc`` and ``bcc``.

Parameters may be overridden via ``__init__``.

ImagesMixin
-----------
The mixin allows to embed images into email via ``<img src="cid:<your image>">`` in HTML.
To enable this functionality set ``images`` and ``images_root`` class fields.

| ``images_root`` - a root path to resolve image paths (e.g. ``os.path.dirname(__file__)`` or ``os.getcwd()``)
| ``images`` - a list of paths to images (e.g. ``['logo.png']`` or ``['email_images/logo.png']``)

Installation
============
::

pip install django-mail-utils
::


Examples
========

TemplateMixin
--------------------
::

from mail_utils import TemplateMixin


class RegistrationEmail(TemplateMixin, EmailMessage):
template_name = 'emails/registration.html'
template_context = {'from': 'Acme Corporation'}
::

EnvelopeMixin
---------------------
::

from mail_utils import EnvelopeMixin

class NotificationEmail(EnvelopeMixin, EmailMessage):
subject = 'Admin News'
from_email = ADMIN_EMAIL
to = COLLEGUES_EMAILS
cc = CC_EMAILS
bcc = BCC_EMAILS
::

ImagesMixin
-----------
::

from mail_utils import TemplateMixin, ImagesMixin

class CoolEmail(ImagesMixin, TemplateMixin, EmailMessage):
template_name = 'email.html'
images_root = os.path.dirname(__file__)
images = ['logo.png', 'phone_icon.png']
::

In HTML use ``<img src="cid:<path from images>">`` to embed an image.

::

<img src="cid:logo.png" /> Company

<img src="cid:phone_icon.png"> Call us
::

Project details


Release history Release notifications

History Node

0.3.1

This version
History Node

0.3

History Node

0.2.1

History Node

0.2

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
django-mail-utils-0.3.tar.gz (3.4 kB) Copy SHA256 hash SHA256 Source None Apr 30, 2014

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page