Reputation: 146
To send email with an HTML tag, I use django-templated-email. How can I change the subject?
send_templated_mail(
template_name='druduser/views/register_email',
from_email=settings.DEFAULT_FROM_EMAIL,
recipient_list=[email],
context={'username': username,},
)
I found the solution:
I have to put {% block subject %}
block out of {% block html %}
...
Thanks for your help!
Upvotes: 2
Views: 542
Reputation: 474211
Quote from docs:
For legacy purposes you can specify email subjects in your settings file (but, the preferred method is to use a {% block subject %} in your template)
So, you can specify a custom subject right in your template by defining a subject
block: see docs.
If you want to go with TEMPLATED_EMAIL_DJANGO_SUBJECTS
setting, template_name
should be just a name of the actual template (without extension).
Define TEMPLATED_EMAIL_DJANGO_SUBJECTS
dictionary in settings.py
, e.g.:
TEMPLATED_EMAIL_DJANGO_SUBJECTS = {
'welcome':'Welcome to my website',
}
Define where to get templates and a file extension:
TEMPLATED_EMAIL_TEMPLATE_DIR = 'templated_email/' #Use '' for top level template dir
TEMPLATED_EMAIL_FILE_EXTENSION = 'email'
Then just send the mail using welcome
as a template_name
:
send_templated_mail(
template_name='welcome',
from_email=settings.DEFAULT_FROM_EMAIL,
recipient_list=[email],
context={'username': username,},
)
In this case your template should be in templated_email/welcome.email
.
Hope that helps.
Upvotes: 2