0

I'm trying to send emails using Django without success.
I configured the settings.py file as below:

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = "xxx@gmail.com"
EMAIL_HOST_PASSWORD = "xxx"
EMAIL_PORT = 587
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'

I wrote a very simple view to test email sending:

def send_email_test(request):
        from_email = "xxx@gmail.com"
        to = "yyy86@gmail.com"
        send_mail("test oggetto", "test messaggio", from_email, [to], fail_silently=False)
        print "email sent"
        return render_to_response('index.html', context_instance=RequestContext(request))

On my server console I can see this log:

Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Subject: test oggetto
From: xxx@gmail.com
To: yyy@gmail.com
Date: Thu, 09 Jul 2015 09:18:47 -0000
Message-ID: <20150709091847.28525.42497@MyServer>

test messaggio
-------------------------------------------------------------------------------
email sent

Anyway, I do not receive the mail on my email account.
Any suggestion?

neoben
  • 743
  • 12
  • 30
  • you are overriding EMAIL_BACKEND in your settings. remove the second EMAIL_BACKEND assignment\ – Ajay Gupta Jul 09 '15 at 09:53
  • This answer is for php related issue, but it's valid here as well: https://stackoverflow.com/questions/21937586/phpmailer-smtp-error-password-command-failed-when-send-mail-from-my-server/25175234#25175234 – callmebob May 09 '22 at 14:20

2 Answers2

1

Well, you're using the ConsoleBackend, which as the name implies simply prints the email to the console, for testing.

I expect you want django.core.mail.backends.smtp.EmailBackend, as described in the documentation.

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
  • Sorry it was a typo. I'm just using `EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'` and not `EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'` , but right now I receive an `SMTPAuthenticationError` – neoben Jul 09 '15 at 09:53
1

It was an issue related to the security settings of my Google account.
If some of you has the same problem, you need to allow access to your Google account using external application.
Use the following link:
https://accounts.google.com/b/0/DisplayUnlockCaptcha

Then click on Continue button and access your Google account using your application within the next 30 seconds.

neoben
  • 743
  • 12
  • 30
  • Some more explanation and same answer here: https://stackoverflow.com/questions/21937586/phpmailer-smtp-error-password-command-failed-when-send-mail-from-my-server/25175234#25175234 – callmebob May 09 '22 at 14:21