I wanted to send an email with Django(1.5), in my console it looked like the following:

In [30]: send_mail("bla", "here it is", "[email protected]", 
["[email protected]"], fail_silently=False)

Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Subject: bla
From: [email protected]
To: [email protected]
Date: Sat, 14 Dec 2013 11:56:37 -0000
Message-ID: <20131214115637.4720.60719@my_username-E531>

here it is
-------------------------------------------------------------------------------
Out[30]: 1

Eventually I found the problem was caused because EMAIL_BACKEND (containing django.core.mail.backends.smtp.EmailBackend) in settings.common.py was being overwritten by EMAIL_BACKEND (containing django.core.mail.backends.console.EmailBackend) in settings.dev.py with a different value.

The only explicit clue I had that something went wrong was Out[30]: 1, as I understand an exit status of an unsuccessful run of a process.

  1. How come I didn't get any Python error?
  2. Was there a way to get the Python error for this error? If this was not possible how should I have debugged this properly?
1

There are 1 answers

5
Martijn Pieters On BEST ANSWER

The return value you see is the number of messages processed. From the django.core.mail.backends.base.BaseEmailBackend.send_messages() method:

def send_messages(self, email_messages):
    """
    Sends one or more EmailMessage objects and returns the number of email
    messages sent.
    """

The backend you are using, even though it is the wrong one, is indicating it sent 1 message.

If this is the django.core.mail.console.EmailBackend() backend, that just means 1 message was written to sys.stdout, but otherwise not forwarded to a SMTP server.