Skip to main content


Project description

# Django Firstclass
Firstclass is a proxy email backend for Django that allows for global email transformations
such as automatically create a plain text version of html emails.

## Install
pip install django-firstclass

- Add ``'firstclass'`` to ``INSTALLED_APPS``
- Add ``url(r'^email/', include('firstclass.urls'))`` to your urlconf.
- Set ``EMAIL_BACKEND`` to ``'firstclass.backends.ProxyBackend'``
- Run ``python syncdb``

## Settings
The email backend to send processed emails to after they've gone through the middleware.

Default: ``'django.core.mail.backends.smtp.EmailBackend'``

Firstclass middleware works just like Django middleware. Firstclass applies middleware
in the order it's defined in ``FIRSTCLASS_MIDDLEWARE``, top-down. You can even create your
own middleware. See: [Custom Middleware](#custom-middleware)


## Available Middleware
### PlainTextMiddleware

#### Settings
A dictionary of rules for converting html to plain text. Keys should be a qualified
selector for BeautifulSoup's ``findAll``. Values can either be a formatting string or
a function that accepts one argument, ``attrs``. All attributes found on the element
can be used for formatting or will be passed to your function in ``attrs``.

'a': '(%(text)s) %(href)s',
'img': '%(title)s: %(src)s',

### MultiAlternativesMiddleware

Coerces email to ``EmailMultiAlternatives`` so that a multiple versions of the
email can be added.

### ViewOnlineMiddleware

Saves all emails and adds a link to the email body so that they can be viewed online
in a web browser. Ideally this middleware should come before the ``PlainTextMiddlewware``
so that the link that is added is converted to plain text.

``ViewOnlineMiddleware`` uses the template ``firstclass/view_online_wrap.html`` to append
the link to the bottom of the email. You can override this by providing your own in your
templates directory.

## Custom Middleware
Defining custom middleware for Firstclass is simple. Middleware should be a single
Python class that defines ``process_message``.

### process_message
``process_message(self, message)``

``message`` is an [EmailMessage](
or an ``EmailMessage`` like object. ``process_message`` should return ``message``
or ``None``. If it returns ``None`` the email will be dropped.

## Views
### view_message_online
``firstclass.views.view_message_online(request, key, template='firstclass/message.html')``

This view is used by the ``ViewOnlineMiddleware`` middleware. It's template is
located at ``firstclass/message.html``. You can override this by providing your own
in your templates directory. The render context contains ``message`` which is ``Message``
model instance.

Project details

Download files

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

Files for django-firstclass, version 0.9
Filename, size File type Python version Upload date Hashes
Filename, size django-firstclass-0.9.tar.gz (5.4 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page