Skip to main content
# Django Firstclass
Firstclass is a proxy email backend for Django that allows for global email transformations
such as automatically creating a plain text version of html emails or automatically creating
an online version of the email that can be read in browser.

## Install
```bash
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'``
- Syncdb

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

##### Default
```python
FIRSTCLASS_EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
```

### FIRSTCLASS_MIDDLEWARE
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)

##### Default
```python
FIRSTCLASS_MIDDLEWARE = (
'firstclass.middleware.online.ViewOnlineMiddleware',
'firstclass.middleware.alternative.MultiAlternativesMiddleware',
'firstclass.middleware.text.PlainTextMiddleware',
)
```

## Available Middleware
### PlainTextMiddleware
``firstclass.middleware.text.PlainTextMiddleware``

#### Settings
##### FIRSTCLASS_PLAINTEXT_RULES
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``.

##### Default
```python
FIRSTCLASS_PLAINTEXT_RULES = {
'a': '(%(text)s) %(href)s',
'img': '%(title)s: %(src)s',
}
```

### MultiAlternativesMiddleware
``firstclass.middleware.alternative.MultiAlternativesMiddleware``

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

### ViewOnlineMiddleware
``firstclass.middleware.online.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.

#### Settings
##### FIRSTCLASS_VIEWONLINE_AUTH
If this is ``True`` the user will need to be logged in to view email. The user's email would
also need to be one of the original recipients of the email.

##### Default
```python
FIRSTCLASS_VIEWONLINE_AUTH = False
```

## 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](https://docs.djangoproject.com/en/dev/topics/email/?from=olddocs/#emailmessage-objects)
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.

Metadata

Release files for django-firstclass 0.9.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-firstclass 0.9.1
File Size Uploaded Provenance Actions
django-firstclass-0.9.1.tar.gz 6.5 kB Without provenance Details for django-firstclass-0.9.1.tar.gz

Release files / django-firstclass-0.9.1.tar.gz

Download URL django-firstclass-0.9.1.tar.gz
Size 6.5 kB
Tags Source
SHA-256 checksum
How to use checksums
c6c63d02d2fa3b290c7451ce8ca71a155e3be2afcd7e8fa96cd66b879f76e97a
BLAKE2b-256 checksum
How to use checksums
667ede25f3adb0b448e380c0b6188dd6d6a209d11632c58d7df1fca3a275737a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for django-firstclass 0.9.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page