[ACCEPTED]-How can I know if a email is sent correctly with Django/Python?-django

Accepted answer
Score: 10

When running unit tests emails are stored 7 as EmailMessage objects in a list at django.core.mail.outbox you can then perform 6 any checks you want in your test class. Below 5 is an example from django's docs.

from django.core import mail
from django.test import TestCase

class EmailTest(TestCase):
    def test_send_email(self):
        # Send message.
        mail.send_mail('Subject here', 'Here is the message.',
            'from@example.com', ['to@example.com'],

        # Test that one message has been sent.
        self.assertEqual(len(mail.outbox), 1)

        # Verify that the subject of the first message is correct.
        self.assertEqual(mail.outbox[0].subject, 'Subject here')

Alternatively if you 4 just want to visually check the contents 3 of the email during development you can 2 set the EMAIL_BACKEND to:

EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'

and then look at you console.

or 1

EMAIL_BACKEND = 'django.core.mail.backends.filebased.EmailBackend'
EMAIL_FILE_PATH = '/tmp/app-messages' # change this to a proper location

then check the file.

Score: 9

There is no way to check that a mail has 5 actually been received. This is not because 4 of a failing in Django, but a consequence 3 of the way email works.

If you need some 2 form of definite delivery confirmation, you 1 need to use something other than email.

Score: 3

This post on integrating Django with Postmark describes how 1 you can follow-up on e-mail delivery.

Score: 2

In case of error, send_mail should raise an exception. The 3 fail_silently argument makes possible to 2 ignore the error. Did you enable this option 1 by mistake?

I hope it helps

More Related questions