Skip to main content

Django Debug Toolbar - Mail Panel

Testing and debugging e-mail while developing a Django app has never been pleasant. Sending e-mail to a file-based backend requires a user to click through obtusely-named files and does not provide a way to preview rendered HTML. Sending e-mail to a valid mailbox incurs a delay as the message is processed though a mail server, and clutters a developer's inbox.

The mail panel attempts to address these problems by providing a way to preview emails within the browser using django-debug-toolbar.

This mail panel is released under the Apache license. If you like it, please consider contributing!

Special thanks to @ShawnMilo for the code review.

Installation

To install the mail panel, first install this package with pip install django-mail-panel. Then add the mail_panel app after debug_toolbarto the INSTALLED_APPS setting:

INSTALLED_APPS = (
    ...
    'debug_toolbar',
    'mail_panel',
)

and add the panel DEBUG_TOOLBAR_PANELS:

DEBUG_TOOLBAR_PANELS = (
    ...
    'mail_panel.panels.MailToolbarPanel',
)

Collect static and you'll be good to go.

./manage.py collectstatic

Configuration

After installation, you now need to redirect mail to the mail toolbar. Change your email backend to the following:

EMAIL_BACKEND = 'mail_panel.backend.MailToolbarBackend'

Important: This plugin uses Django's cache backend to store messages. If you are using DummyCache, the mail panel will use a local memory cache, and will reset messages when the server is restarted.

[Optional] By default, mail toolbar stores messages for one day before removing them from cache. You can change this with the following setting:

MAIL_TOOLBAR_TTL = 86400  # 1 Day

[Optional] If you use the DEBUG_TOOLBAR_PANELS to custom order your panels:

    DEBUG_TOOLBAR_PANELS = [
        "debug_toolbar.panels.history.HistoryPanel",
        "debug_toolbar.panels.versions.VersionsPanel",
        "debug_toolbar.panels.timer.TimerPanel",
        "debug_toolbar.panels.settings.SettingsPanel",
        "debug_toolbar.panels.headers.HeadersPanel",
        "debug_toolbar.panels.request.RequestPanel",
        "debug_toolbar.panels.sql.SQLPanel",
        "debug_toolbar.panels.staticfiles.StaticFilesPanel",
        "debug_toolbar.panels.templates.TemplatesPanel",
        "debug_toolbar.panels.cache.CachePanel",
        "debug_toolbar.panels.signals.SignalsPanel",
        "debug_toolbar.panels.logging.LoggingPanel",
        "debug_toolbar.panels.redirects.RedirectsPanel",
        "debug_toolbar.panels.profiling.ProfilingPanel",
        "mail_panel.panels.MailToolbarPanel",  # reposition to desired location
    ]

Testing

To preview emails sent from your test suite, add the email backend override to your tests with the following:

from django.test.utils import override_settings

@override_settings(EMAIL_BACKEND='mail_panel.backend.MailToolbarBackend')
def test_send_email(self):
    # your code here

The backend works similarly to the standard email backend and code should not need to be reworked when using the MailToolbarBackend.

from django.core import mail

original_outbox = len(mail.outbox)
# Send mail ...
assert(len(mail.outbox) == original_outbox + 1)

Contributing

Install the development dependencies:

poetry install --with dev

Run the tests on your current python:

pytest .

Shameless Plugs

Like Django Mail Panel? Be sure to check out and support this other tool for Mac that will improve your workflow:

Red - A visual and interactive Redis client, featuring live updating keys, an interactive console, pub/sub, lua script support and much more.

Metadata

Release files for django-mail-panel 6.0.0

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-mail-panel 6.0.0
File Size Uploaded
django_mail_panel-6.0.0.tar.gz 15.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-mail-panel 6.0.0
File Interpreter ABI Platform
django_mail_panel-6.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 33.2 kB

Release files / django_mail_panel-6.0.0.tar.gz

Download URL django_mail_panel-6.0.0.tar.gz
Size 15.6 kB
Tags Source
SHA-256 checksum
How to use checksums
b287673758f9e2275e694f0b76f4fab2317d3c6ec6eb876450160bd90796c18b
BLAKE2b-256 checksum
How to use checksums
acb92e13d3fa539444071da567599f0317bd056fc0d68440ab8a093fb1d87828
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.3 CPython/3.11.1 Darwin/24.2.0

Release files / django_mail_panel-6.0.0-py3-none-any.whl

Download URL django_mail_panel-6.0.0-py3-none-any.whl
Size 17.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0e4cad477791af48f275e19096b312d29bc2eec47aef3d160fcba06baf58563f
BLAKE2b-256 checksum
How to use checksums
71df431d87d1fd85fd1674d6bdac4fb98abc1ba0707a24503def8cc99212a46c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.3 CPython/3.11.1 Darwin/24.2.0

Release history Release notifications | RSS feed

This release

6.0.0 This release

2 release files

4.1.1

2 release files

4.1

2 release files

4.0.4

2 release files

4.0.3

2 release files

4.0.2

2 release files

4.0.1

2 release files

4.0.0

2 release files

3.2.6

2 release files

3.2.5

2 release files

3.2.4

2 release files

3.2.3

2 release files

3.2.2

2 release files

3.2.1

2 release files

3.2

2 release files

3.1

2 release files

1.2.5

2 release files

1.2.4

2 release files

1.2.3

2 release files

1.2.2

2 release files

1.2.1

1 release file

1.2.0

2 release files

1.1.0

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

1 release file

1.0.4

1 release file

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

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