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 messagesMITOL_MAIL_REPLY_TO_ADDRESS
- the default reply-to email for all messagesMITOL_MAIL_MESSAGE_CLASSES
- a list of fully qualified message class names that make the message classes available in the debuggerMITOL_MAIL_ENABLE_EMAIL_DEBUGGER
-True
if the email debugger should be enabled, you probably want to set this to the same value asDEBUG
MITOL_MAIL_RECIPIENT_OVERRIDE
- only used locally, this overrides the recipient of all outgoing email messagesMITOL_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 builtinUser
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 thatanymail
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 withintemplates/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 adict
. As a best practice you should be merging withsuper().get_base_template_context()
.get_default_headers
- extend the default headers included with all emails of this type. Return type is adict
. As a best practice you should be merging withsuper().get_default_headers()
.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file mitol-django-mail-2023.1.17.tar.gz
.
File metadata
- Download URL: mitol-django-mail-2023.1.17.tar.gz
- Upload date:
- Size: 16.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0ca6823bec6212003d59eb1ce61cfb8f95bbf1d418ca47049dda77f2bd9c5070 |
|
MD5 | 5dbf9307afda3d4ca02d4baf65c71750 |
|
BLAKE2b-256 | 93d446a4319397c3dba189ad0b64d1da208b5e14b7e9b284c9a70982f0c4533c |
File details
Details for the file mitol_django_mail-2023.1.17-py3-none-any.whl
.
File metadata
- Download URL: mitol_django_mail-2023.1.17-py3-none-any.whl
- Upload date:
- Size: 19.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e7dc968950c02854bde69b5cfcf282a20eb334ba469a126d451edd72dfe0020c |
|
MD5 | f7f78979d5fa01006c3d9210947f8a43 |
|
BLAKE2b-256 | c7eb695f0ec35cde169ac1e20bb182a5ef73db5c132b6b59ae27a850b7062cc9 |