0

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?

Lelouch
  • 2,111
  • 2
  • 23
  • 33

2 Answers2

4

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

karthikr
  • 97,368
  • 26
  • 197
  • 188
0

Please you can add send_mail(..other keywords like the from mail....,fail_silently=False) this can help you get the error by default if the mail fail you wont know because it skips it

And also check the email backend if it is console or smtp make sure it is django.core.mail.backends.smtp.EmailBackend and the host must not be localhost

Codertjay
  • 588
  • 8
  • 13