About Testing Emails

You can test the outgoing emails by setting EMAIL_BACKEND = "django.core.mail.backends.locmem.EmailBackend" in the settings and then using the django.core.mail module, as follows:

1
2
3
4
5
6
7
8
from django.core import mail

email = mail.outbox[0]
from_email = email.from_email
to_emails = email.to
subject = email.subject
plain_text_message = email.body
html_message, mime_type = email.alternatives[0]

Tips and Tricks Programming Testing Django 5.x Django 4.2 Django 3.2 Django 2.2