Package: django-mdmail
AboutMarkdown-mail support forDjangoviamdmail.Django is a popular web framework which contains its own wrapper functions for sending email, written in Python.mdmailis a Python library for sending email in both plaintext and HTML forms, using glorious markdown.This simple library wraps those two elements together, allowing users of Django to easily use Django's built-in facilities to send email in markdown instead of a combination of plaintext and HTML.The most important design goal of this library is to allow a Django user to replace...from django.core.mail import send_mail...with...from django_mdmail import send_mail...to send markdown emails with all the features of the Django email functionality intact.Installationpip install django_mdmailNotes on parametersParameters frommdmailcssThe parametercsscan be used with both thesend_mailandconvert_md_templatesfunctions, which then gets moved forward tomdmail's underlying function,EmailContent. Thecssparameter should containCSS as text, not as a filename.Parameters fromdjango.core.mail.send_mailhtml_messageThe parameterhtml_messagecan be used with thesend_mailfunction to override the HTML generated from markdown, although that completely defies the whole point of usingdjango_mdmailin the first place. It is provided for API compatibility.Template-driven emailsIn Django and some libraries written for it, emails are formed from Django templates, such as for confirmations of various sorts and resetting forgotten passwords. Such mechanisms typically assume one template for plaintext emails and another one for HTML emails, forcing a Django user to maintain two separate versions of the same content, one in plaintext and one in HTML.Using this library, a single markdown file can be written with an.mdfilename ending which is then generated into both a.txtversion and.htmlversion when a Django server is started. This is done through AppConfig as per the following example, where the app's name iscoreand the following contents are incore/apps.py:from django.apps import AppConfig
from django_mdmail import convert_md_templates

class CoreConfig(AppConfig):
    name = 'core'

    # A function that is run by Django at server startup (not per page hit).
    def ready(self):
        # Converts markdown templates (`.md`) into plaintext (`.txt`) and HTML (`.html`) templates.
        convert_md_templates()Note: If you copy-paste this code and your app's name is "whatever", you need to replace "core" with "whatever" and "CoreConfig" with "WhateverConfig". See thedocumentation onAppConfig.ready()for details.Assuming that this code runs without failure, then all you need to do in order to get markdown-generated.txtand.htmltemplates, is to write a template in markdown using the file ending.mdin a proper template directory. It will be chopped down into corresponding.txtand.htmlfiles which will then be used by whatever internal or built-in email functionality you are using.ImagesImages by URL are supported, with the caveat that if a user is using a responsible email client that respects people's privacy, the images will not be automatically shown, but only if the user specifically requests them. This may be problematic for a message that relies too heavily on images for either communication or aesthetics.Inline images are supported but they must be available on the server that sends the email (the Django server) and the image link in the markdown message must be relative to the Django project's root. This is partly a limitation ofmdmail, but if you host your images on the same server as the Django instance that sends the emails,you can indeeduse inline images that even the most annoyingly responsible email clients will display, assuming they render HTML in the first place.Known limitationsInline images are not supported in emails rendered from templates.