djangosmtpdjango-email

django send_email() shows success but no email received


I am learning how to send an email in Djgnao. I have configured

# settings.py
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'

EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = '<my username>@gmail.com'
EMAIL_HOST_PASSWORD = '<my password>'
EMAIL_PORT = 587
EMAIL_USE_TLS = True

and in django shell I try to send an email to my self (and my friend also)

>>> from django.core.mail import send_mail
>>> send_mail('Subject here', 'Here is the message.', "<my username>@gmail.com", ["<my username>@gmail.com"])

and it returns result which looks successful

MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Subject: Subject here
From: <my username>@gmail.com
To: <my username>@gmail.com
Date: Wed, 21 Jan 2015 17:55:20 -0000
Message-ID: <20150121175520.31612.19817@<my username>>

Here is the message.
---------------------------------------------------------------------
1

But checking my email and my friend's email inbox, there is no such email received.

Am I misunderstanding something? Or do I need to do something with my Gmail account?


Actually, I tried the [Sign in to Admin Console] in https://support.google.com/a/answer/182076?hl=en, but I got redirected in between "re-enter your password" page and "choose an account or add a new account" page. I am trying my free, ordinary personal Google account, would that be the problem?


Solution

  • The issue is, your setting is

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

    This means that the email message prints to console.

    Instead of sending out real emails the console backend just writes the emails that would be sent to the standard output. By default, the console backend writes to stdout. You can use a different stream-like object by providing the stream keyword argument when constructing the connection.

    Change that to

    EMAIL_BACKEND = django.core.mail.backends.smtp.EmailBackend
    

    for SMTP to work. Here is the relevant documentation