Skip to main content

MIT Open Learning django app extensions for mail

Project description

mitol-django-mail

This is the Open Learning Django Mail app. It provides a few key features around mail:

  • Templated multipart html emails
  • Automatic generation of plaintext portion of multipart email
  • CSS inlining for email html

Getting started

pip install mitol-django-mail

Add the mail app:

INSTALLED_APPS = [
    ...
    "mitol.mail.apps.MailApp",
]

Settings

Common Django settings

  • SITE_BASE_URL - the website's host url, including the protocol (e.g. "https://example.com/")
  • SITE_NAME - the website's name

Mail app settings

All settings for the mitol-django-mail app are namespaced in django settings with MITOL_MAIL_ prefix.

  • MITOL_MAIL_FROM_EMAIL - the default from email for all messages
  • MITOL_MAIL_REPLY_TO_ADDRESS - the default reply-to email for all messages
  • MITOL_MAIL_MESSAGE_CLASSES - a list of fully qualified message class names that make the message classes available in the debugger
  • MITOL_MAIL_ENABLE_EMAIL_DEBUGGER - True if the email debugger should be enabled, you probably want to set this to the same value as DEBUG
  • MITOL_MAIL_RECIPIENT_OVERRIDE - only used locally, this overrides the recipient of all outgoing email messages
  • MITOL_MAIL_FORMAT_RECIPIENT_FUNC - (optional) set to a custom function to format recipients. You'll typically use this if you're storing the name in a place other that Django's builtin User model. Default: "mitol.mail.defaults.format_recipient".
  • MITOL_MAIL_CAN_EMAIL_USER_FUNC - (optional) set to a custom function to determine whether a user can be sent an email. You'll typically use this if you have additional criteria beyond the user having an email. Default: "mitol.mail.defaults.can_email_user".
  • MITOL_MAIL_CONNECTION_BACKEND - the connection backend to use for email sending. You'd use this only if you're doing something really custom that anymail doesn't give you. Default: "anymail.backends.mailgun.EmailBackend".

Usage

Create message classes

This involves subclassing mitol.mail.messages.TemplatedMessage. To subclass, do the following:

  • template_name attribute - str that denotes the directory within templates/mail that this message's templates reside in (e.g. "password_reset")
  • name attribute - a human-friendly name for your message (e.g. "Password Reset")
  • get_debug_template_context - static method that returns a context dict for rendering the email in the debugger

Define templates

In your apps's templates directory, create some templates:

templates/
  mail/
    {template_name}/
      subject.txt
      body.html

Configure settings.py

Add your custom message class to MITOL_MAIL_MESSAGE_CLASSES so it is available in the debugger.

Optional customizations

Optionally, you can also override:

  • get_base_template_context - extend the default base template context used with all emails of this type. Return type is a dict. As a best practice you should be merging with super().get_base_template_context().
  • get_default_headers - extend the default headers included with all emails of this type. Return type is a dict. As a best practice you should be merging with super().get_default_headers().

Project details


Download files

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

Source Distribution

mitol_django_mail-2026.4.2.tar.gz (13.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mitol_django_mail-2026.4.2-py3-none-any.whl (18.8 kB view details)

Uploaded Python 3

File details

Details for the file mitol_django_mail-2026.4.2.tar.gz.

File metadata

  • Download URL: mitol_django_mail-2026.4.2.tar.gz
  • Upload date:
  • Size: 13.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for mitol_django_mail-2026.4.2.tar.gz
Algorithm Hash digest
SHA256 d57eade44d8cdfb0e75f93f0aa3a1b8407fb8c34fe1ae4dc0060ba928c93be6b
MD5 4e8b20fbc7115ccd8933b95372b0df4c
BLAKE2b-256 1e3263b71c97f49567da824ab79defde6fe020a51115ca2fbcbce8510e36bd63

See more details on using hashes here.

File details

Details for the file mitol_django_mail-2026.4.2-py3-none-any.whl.

File metadata

File hashes

Hashes for mitol_django_mail-2026.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f78695194850afcc7f11247168e00d5a57ff65fae7004427e7f39cb9f3c50f6b
MD5 f21836772e9fd2c4b0d5a657f9459d5c
BLAKE2b-256 91b495ce066b4fe6e7bc4dad5b2494ac4eaa426aec9f2515021ea733e97e8fbb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page