# Settings Guide There are several settings available to ensure `django-templated-email-md` can be configured for your needs. The only one that is **required** is `TEMPLATED_EMAIL_BACKEND`. ## Core Settings ### `TEMPLATED_EMAIL_BACKEND` - **Default:** None - **Required:** Yes - **Type:** String - **Description:** The backend class to use for processing Markdown email templates. - **Example:** ```python TEMPLATED_EMAIL_BACKEND = 'templated_email_md.backend.MarkdownTemplateBackend' ``` ### `TEMPLATED_EMAIL_TEMPLATE_DIR` - **Default:** 'templated_email/' - **Required:** No - **Type:** String - **Description:** Directory where email templates are stored. Must include a trailing slash. This is set by default in the `django-templated-email` package. - **Example:** ```python TEMPLATED_EMAIL_TEMPLATE_DIR = 'templated_email/' ``` - **Further Reading:** [Django Template Loading Documentation](https://docs.djangoproject.com/en/stable/topics/templates/#template-loading) ### `TEMPLATED_EMAIL_FILE_EXTENSION` - **Default:** 'md' - **Required:** No - **Type:** String - **Description:** File extension for Markdown template files. - **Example:** ```python TEMPLATED_EMAIL_FILE_EXTENSION = 'md' ``` ### `TEMPLATED_EMAIL_BASE_HTML_TEMPLATE` - **Default:** 'templated_email/markdown_base.html' - **Required:** No - **Type:** String - **Description:** Path to the base HTML template that wraps the Markdown content. See the [usage guide](https://django-templated-email-md.readthedocs.io/en/latest/usage.html) for more information on available approaches to overriding the default template. - **Example:** ```python TEMPLATED_EMAIL_BASE_HTML_TEMPLATE = 'my_app/markdown_base.html' ``` - **Further Reading:** [Django Template Inheritance](https://docs.djangoproject.com/en/stable/ref/templates/language/#template-inheritance) ## Markdown Settings ### `TEMPLATED_EMAIL_MARKDOWN_EXTENSIONS` - **Default:** ['markdown.extensions.extra', 'markdown.extensions.meta', 'markdown.extensions.tables'] - **Required:** No - **Type:** List - **Description:** List of Markdown extensions to enable when processing templates. - **Example:** ```python TEMPLATED_EMAIL_MARKDOWN_EXTENSIONS = [ 'markdown.extensions.extra', 'markdown.extensions.meta', 'markdown.extensions.tables', 'markdown.extensions.codehilite', ] ``` - **Further Reading:** - [Python-Markdown Extensions Documentation](https://python-markdown.github.io/extensions/) - Popular extensions: - [Extra Extension](https://python-markdown.github.io/extensions/extra/) - [Meta Extension](https://python-markdown.github.io/extensions/meta_data/) - [Tables Extension](https://python-markdown.github.io/extensions/tables/) ## URL Settings ### `TEMPLATED_EMAIL_BASE_URL` - **Default:** None - **Required:** No - **Type:** String - **Description:** Base URL to prepend to relative URLs in email templates. - **Example:** ```python TEMPLATED_EMAIL_BASE_URL = 'https://example.com' ``` - **Further Reading:** - [django-templated-email-md Usage Guide](https://django-templated-email-md.readthedocs.io/en/latest/usage.html) - [Django URL Configuration](https://docs.djangoproject.com/en/stable/topics/http/urls/) ## Default Content Settings ### `TEMPLATED_EMAIL_DEFAULT_SUBJECT` - **Default:** 'Hello!' - **Required:** No - **Type:** String - **Description:** Default subject line used when no subject is provided in the template or context. - **Example:** ```python TEMPLATED_EMAIL_DEFAULT_SUBJECT = 'Message from Our Company' ``` ### `TEMPLATED_EMAIL_DEFAULT_PREHEADER` - **Default:** '' - **Required:** No - **Type:** String - **Description:** Default preheader text used when no preheader is provided in the template or context. - **Example:** ```python TEMPLATED_EMAIL_DEFAULT_PREHEADER = 'Important information from Our Company' ``` - **Further Reading:** [Email Preheader Best Practices](https://www.litmus.com/blog/the-ultimate-guide-to-preview-text-support/) (referred to in this blog as 'preview text') ## Branding Settings ### `TEMPLATED_EMAIL_BRANDING` - **Default:** See defaults table below - **Required:** No - **Type:** Dictionary - **Description:** Controls the visual branding of emails rendered by `MarkdownTemplateBackend`. Any keys you provide are merged over the built-in defaults, so you only need to specify the values you want to override. The full set of defaults reproduces the original package styling exactly, ensuring backward compatibility. **Default values:** | Key | Default | Description | |---|---|---| | `primary_color` | `#3498db` | Button backgrounds and accents | | `link_color` | `#3498db` | Hyperlink color | | `heading_color` | `#000000` | Color for h1-h4 headings | | `text_color` | `#333333` | Body paragraph text color | | `background_color` | `#f6f6f6` | Page/email background color | | `container_background` | `#ffffff` | Inner content container background | | `font_family` | `sans-serif` | Font stack for body and headings | | `logo_url` | `""` | URL of the logo image; empty = no logo rendered | | `logo_alt` | `""` | Alt text for the logo image | | `logo_width` | `"200"` | Width of the logo image in pixels (as a string) | - **Example:** ```python TEMPLATED_EMAIL_BRANDING = { "primary_color": "#e74c3c", "link_color": "#e74c3c", "heading_color": "#2c3e50", "text_color": "#555555", "background_color": "#f0f0f0", "container_background": "#ffffff", "font_family": "Georgia, serif", "logo_url": "https://cdn.example.com/logo.png", "logo_alt": "Acme Corp", "logo_width": "180", } ``` > **Tip:** If you only want to change one or two colors, you can set just those keys and all other defaults will be preserved automatically. ## Plain Text Generation Settings ### `TEMPLATED_EMAIL_HTML2TEXT_SETTINGS` - **Default:** {} - **Required:** No - **Type:** Dictionary - **Description:** Configuration options for html2text when generating plain text versions of emails. - **Some of the Available Options:** - `ignore_links`: Exclude links from plain text output - `ignore_images`: Exclude image descriptions - `body_width`: Maximum line width before wrapping - `ignore_emphasis`: Exclude emphasis markers - `mark_code`: Wrap code blocks with backticks - `wrap_links`: Wrap URLs in angle brackets - **Example:** ```python TEMPLATED_EMAIL_HTML2TEXT_SETTINGS = { 'ignore_links': False, 'ignore_images': True, 'body_width': 0, 'ignore_emphasis': True, 'mark_code': False, 'wrap_links': False, } ``` - **Further Reading:** [Available html2text Options](https://github.com/Alir3z4/html2text/blob/master/docs/usage.md#available-options) ## Error Handling Settings ### `TEMPLATED_EMAIL_FAIL_SILENTLY` - **Default:** False - **Required:** No - **Type:** Boolean - **Description:** If True, suppresses exceptions during email rendering and sends fallback email instead. - **Example:** ```python TEMPLATED_EMAIL_FAIL_SILENTLY = True ``` ## HTML Sanitization Settings > **Note:** HTML sanitization requires the optional `nh3` dependency. Install it with: > > ```bash > pip install django-templated-email-md[sanitize] > ``` > > If `TEMPLATED_EMAIL_SANITIZE = True` but `nh3` is not installed, email sending will > raise `ImportError` - install the `[sanitize]` extra to resolve it. This error is > raised even when `TEMPLATED_EMAIL_FAIL_SILENTLY = True`, because silently skipping > requested sanitization would be a security risk. ### `TEMPLATED_EMAIL_SANITIZE` - **Default:** `False` - **Required:** No - **Type:** Boolean - **Description:** When `True`, sanitizes the HTML produced from the Markdown `content` block before it is wrapped in the base template. Uses the `nh3` library (Python bindings for the Rust `ammonia` crate) to strip dangerous constructs such as `