Lesson 14 / 22 · Commentail 1.3.2
Each email has a subject, plain text and HTML. Update both bodies together because some clients display only text. Start with email confirmation.
Create three files
In the project's template directory create commentail/emails/confirm_subject.txt:
{% load i18n %}{% autoescape off %}{% trans "Confirm your email" %} — {{ site_name }}{% endautoescape %}
Keep the subject nonempty and on one line. Create commentail/emails/confirm.txt:
{% load i18n %}{% autoescape off %}{% trans "Confirm your email" %}
{{ site_name }}
{{ action_url }}
{% trans "Open the link and confirm on the next page." %}
{% endautoescape %}
Then commentail/emails/confirm.html:
{% load i18n %}<!doctype html>
<html><body>
<h1>{% trans "Confirm your email" %}</h1>
<p>{{ site_name }}</p>
<p><a href="{{ action_url }}">{% trans "Open confirmation page" %}</a></p>
<p>{% trans "Open the link and confirm on the next page." %}</p>
</body></html>
The English {% trans %} strings belong to your project's translation catalog. Add and compile project translations for other languages; the package catalog need not contain your new wording. A bilingual site needs both translations.
Disable autoescaping only for plain text so names and URL query separators remain literal. Retain HTML escaping. The actual confirmation happens on the opened page, so do not promise that merely opening the email link completes it.
Cover the other kinds
Use the same paths for edit, published, rejected and reply: each has <kind>_subject.txt, <kind>.txt and <kind>.html. Publication/rejection also cover author revisions; distinguish them with is_revision. An empty HTML override creates an empty HTML part rather than disabling multipart mail.
Available variables are only kind, author_name, site_name, site_url, target_url, action_url, view_url, reason, is_revision and expires_at. Rejection supplies reason; confirmation supplies view_url. URLs are absolute. There is no request, recipient email or internal comment model. Reply notices must contain metadata and links rather than reply text or excerpts.
Shared emails/base.html and button.html are presentation helpers, not an additional stable API. Override all five HTML bodies for an independent design.
Inspect the messages
Begin with the console backend on a practice site. Exercise confirmation, publication, editing, rejection and a direct reply. Inspect both MIME alternatives and the subject. Rendering uses the saved recipient language even when the worker's language differs.
Then send through the chosen real backend to an address you control and inspect an actual email client. Syntax or subject errors fail the job; correct the template and retry while its original link remains valid.
Related lessons
- 6. Send email through SMTP
- 7. Use the Resend API through Django Anymail
- 8. Schedule email processing and cleanup
Choose a sign-in method or comment as a guest below.