An extension for django-templated-email for creating emails with Markdown
Project description
django-templated-email-md
Features
- Markdown Templates: Write email templates using Markdown syntax for cleaner and more readable templates.
- Automatic Conversion: Automatically converts Markdown to HTML and generates a plain text version of emails.
- CSS Inlining: Inlines CSS styles for better email client compatibility using Premailer.
- Seamless Integration: Works as an extension of
django-templated-email
, allowing for easy integration into existing projects. - Template Inheritance: Supports Django template inheritance and template tags in your Markdown templates.
Installation
You can install django-templated-email-md
via pip from PyPI:
pip install django-templated-email-md
Add to INSTALLED_APPS
Add templated_email_md
to your INSTALLED_APPS
in settings.py
:
INSTALLED_APPS = [
# ...
'templated_email_md',
# ...
]
Configuration
Assuming you have already installed and configured django-templated-email, update your Django settings as follows:
# settings.py
# Configure the templated email backend
TEMPLATED_EMAIL_BACKEND = 'templated_email_md.backend.MarkdownTemplateBackend'
# Optional: Specify the base HTML template for wrapping your content. See the Usage guide for details.
TEMPLATED_EMAIL_BASE_HTML_TEMPLATE = 'templated_email/markdown_base.html'
# Set the directory where your email templates are stored
TEMPLATED_EMAIL_TEMPLATE_DIR = 'templated_email/' # Ensure there's a trailing slash
# Define the file extension for your Markdown templates
TEMPLATED_EMAIL_FILE_EXTENSION = 'md'
# Optional: Specify Markdown extensions if needed
TEMPLATED_EMAIL_MARKDOWN_EXTENSIONS = [
'markdown.extensions.extra',
'markdown.extensions.meta',
'markdown.extensions.tables',
]
Usage
Creating Markdown Templates
Place your Markdown email templates in the templated_email/
directory within your project's templates directory. For example, create a file templated_email/welcome.md
:
{% block subject %}Test Email{% endblock %}
{% block preheader %}Thanks for signing up!{% endblock %}
{% block content %}
# {{ user.first_name }}, you're in!
![Gorgeous, golden potato, Spedona, CC BY-SA 3.0 https://creativecommons.org/licenses/by-sa/3.0, via Wikimedia Commons](https://upload.wikimedia.org/wikipedia/commons/a/a4/Icone_pdt.png)
## Welcome to The Potato Shop
### Hello {{ user.fiest_name }}! 👋
> You have been invited to set up an account at the Potato shop on behalf of **{{ inviter.name }}**.
Please click [this link]({% url 'invitations:accept-invite' key=invitation.key %}) to establish your account.
{% blocktranslate %}You will be directed to the 'set password' tool, where you can establish your account password.{% endblocktranslate %}
---
Best regards,
*Jack Linke*
Potato Shop, LLC - Managing Director
*Semi-round, Starchy Veggies for All*
{% endblock %}
Sending Emails
Use the send_templated_mail
function to send emails using your Markdown templates, just as you would with the base django-templated-email package:
from templated_email import send_templated_mail
send_templated_mail(
template_name='welcome',
from_email='Potato Shop Support <support@mashedupyum.com>',
recipient_list=['terrence3725fries@wannamashitup.com'],
context={
'user': request.user,
'inviter': inviter,
},
)
The Result
More detailed information can be found in the usage guide.
Documentation
For more detailed information, please refer to the full documentation.
Contributing
Contributions are very welcome. To learn more, see the Contributor Guide.
License
Distributed under the terms of the MIT license, django-templated-email-md
is free and open source software.
Issues
If you encounter any problems, please file an issue along with a detailed description.
Credits
We are grateful to the maintainers of the following projects:
This project was generated from @OmenApps's Cookiecutter Django Package template.
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 django_templated_email_md-2024.10.4.tar.gz
.
File metadata
- Download URL: django_templated_email_md-2024.10.4.tar.gz
- Upload date:
- Size: 13.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.4.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1405b3d7132cc3df53370e3067d5c5225e65ded7b6398b42a3ce07e366198e1b |
|
MD5 | 8d401fd4c03827608fdc60cdb754db7f |
|
BLAKE2b-256 | 6d52430cce7061120a25607716b8ce7af59d01822edcfabae6c565547734f02e |
File details
Details for the file django_templated_email_md-2024.10.4-py3-none-any.whl
.
File metadata
- Download URL: django_templated_email_md-2024.10.4-py3-none-any.whl
- Upload date:
- Size: 14.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.4.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fd63813b5d7b8714171bad1c394aee24df483177da9efed5c16a0590e7ee1975 |
|
MD5 | c13a5d71d9b80b52e1443a5a60fc3b3d |
|
BLAKE2b-256 | 127752045cf93e55b572701f5787c7d14057b9749c5509f165f8c2527b0e906d |