{"id":8119,"library":"django-templated-mail","title":"Django Templated Mail","description":"Django Templated Mail is a Python library for Django that simplifies sending emails by leveraging Django's powerful template system. It allows developers to define email subject, body (HTML and plain text), and other attributes using standard Django templates. The current version is 1.1.1, and it maintains an active release cadence with regular bug fixes and feature enhancements, particularly for Django version compatibility.","status":"active","version":"1.1.1","language":"en","source_language":"en","source_url":"https://github.com/sunscrapers/django-templated-mail","tags":["django","email","templates","mail"],"install":[{"cmd":"pip install django-templated-mail","lang":"bash","label":"Install stable release"}],"dependencies":[{"reason":"Core framework dependency for templating and email backend.","package":"Django","optional":false},{"reason":"Used for version parsing and compatibility checks.","package":"packaging","optional":false}],"imports":[{"symbol":"BaseEmailMessage","correct":"from templated_mail.mail import BaseEmailMessage"}],"quickstart":{"code":"import os\nimport django\nfrom django.conf import settings\nfrom templated_mail.mail import BaseEmailMessage\n\n# Minimal Django setup for demonstration purposes.\n# In a real Django project, these settings would be in your settings.py\n# and django.setup() would be handled by manage.py.\nos.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproject.settings')\n\nif not settings.configured:\n    settings.configure(\n        INSTALLED_APPS=['templated_mail'],\n        TEMPLATES=[\n            {\n                'BACKEND': 'django.template.backends.django.DjangoTemplates',\n                'DIRS': [],\n                'APP_DIRS': True, # Allows finding templates in app 'templates' subdirectories\n                'OPTIONS': {\n                    'debug': True,\n                },\n            },\n        ],\n        DEFAULT_FROM_EMAIL='noreply@example.com',\n        EMAIL_BACKEND='django.core.mail.backends.console.EmailBackend', # Prints email to console\n    )\n# Ensure Django is set up *after* settings are configured.\ndjango.setup()\n\n# Define your custom email message class.\n# IMPORTANT: You need to create the actual template file in your Django project.\n# For example, create 'my_app/templates/emails/welcome.html' with content like:\n#\n# {% extends \"templated_mail/email.html\" %}\n# {% block subject %}Welcome, {{ user_name }}!{% endblock %}\n# {% block html %}<p>Hello {{ user_name }},</p><p>Thank you for joining our service!</p>{% endblock %}\n# {% block plain %}{% block subject %}{% endblock %} Hello {{ user_name }}, Thank you for joining our service!{% endblock %}\n\nclass WelcomeEmail(BaseEmailMessage):\n    # This path assumes 'emails/welcome.html' is found in one of your TEMPLATES DIRS or APP_DIRS\n    template_name = 'emails/welcome.html'\n\n# Instantiate and send the email\ncontext_data = {'user_name': 'John Doe'}\nemail = WelcomeEmail(context=context_data)\nemail.send(to=['john.doe@example.com'], from_email='noreply@myservice.com')\n\nprint(\"\\nEmail sent (output to console). Check your console for details.\")","lang":"python","description":"This quickstart demonstrates how to define a templated email class and send an email using `django-templated-mail`. It sets up minimal Django settings for a runnable example. Remember to create the actual template file (e.g., `my_app/templates/emails/welcome.html`) in your Django project, extending `templated_mail/email.html` and defining `subject`, `html`, and `plain` blocks."},"warnings":[{"fix":"Update calls from `email.set_context_data()` to `email.get_context_data()`.","message":"The `set_context_data` method on `BaseEmailMessage` was renamed to `get_context_data` in version 1.0.0.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Replace all calls to `email.send_to(...)` with `email.send(...)`.","message":"The method `BaseEmailMessage.send_to` was renamed to `BaseEmailMessage.send` in version 0.2.0 for consistency.","severity":"breaking","affected_versions":">=0.2.0"},{"fix":"Upgrade your Django project to version 1.11 or a later compatible version (e.g., Django 2.0+).","message":"Support for Django 1.10 was removed in version 1.1.0. The library now requires Django 1.11 or higher.","severity":"breaking","affected_versions":">=1.1.0"},{"fix":"Upgrade to `django-templated-mail` version 1.1.1 or higher. Alternatively, explicitly pass the `from_email` argument to the `send` method or set it on the `BaseEmailMessage` instance.","message":"Prior to version 1.1.1, the `from_email` parameter in `BaseEmailMessage.send` did not always correctly fall back to `settings.DEFAULT_FROM_EMAIL` if omitted.","severity":"gotcha","affected_versions":"<1.1.1"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Ensure the template file exists at the correct path (e.g., `your_app/templates/emails/welcome.html`) and that your Django `TEMPLATES` settings correctly include `APP_DIRS=True` or `DIRS` pointing to your template folders.","cause":"Django's template loaders could not find the specified template file for your email.","error":"django.template.exceptions.TemplateDoesNotExist: emails/welcome.html"},{"fix":"Update your code to use `email.send(...)` instead of `email.send_to(...)`. This change was introduced in version 0.2.0.","cause":"You are attempting to use the deprecated `send_to` method, which was renamed to `send`.","error":"AttributeError: 'WelcomeEmail' object has no attribute 'send_to'"},{"fix":"Ensure Django settings are configured and `django.setup()` has been called before using `BaseEmailMessage`. In a typical Django project, `manage.py` handles this. For standalone scripts, you need to explicitly configure settings and call `django.setup()`.","cause":"You are trying to use `django-templated-mail` without a properly configured Django environment.","error":"ImproperlyConfigured: Requested setting TEMPLATES, but settings have not been configured."}]}