0

I was trying to make the custom password reset view for django.contrib.auth.views.password_reset.

I made it by myself (Of course, I see some tutorial articles.)
But when I request the password reset form to the development server,
It shows like this (on the development server log):

Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Subject: Hello
From: <My email address> (Outlook)
To: <My another email address> (GMail)
Date: Wed, 22 Aug 2018 11:44:55 -0000
Message-ID: <20180822114455.3320.17387@Yeonhos-MacBook-Pro.local>
I am testing Django EmailMessage Class

But, It doesn't send anything to my address which is marked as My another email address.
Can anyone help me? Why doesn't Django send this e-mail?

2 Answers2

0

If you're following along a tutorial, then it's possible you have the console email backend configured, which is only useful for debugging - look for this line in your settings.py:

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

To actually send mail, you'll have to configure Django to use the SMTP backend and you'll also need details for a mailserver which will allow you access. To use the SMTP backend replace the line above with the following:

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = '...'  # Your mailserver host
EMAIL_HOST_USER = '...'  # Your mailserver user, if required
EMAIL_HOST_PASSWORD = '...'  # Your mailserver password, if required
kristaps
  • 1,705
  • 11
  • 15
  • Oh I should try it – Yeonho Lee Aug 23 '18 at 12:01
  • As I said, you'll need to find a mailserver which will let you send email - GMail probably doesn't provide public access. If you're on a company or school network, you could ask your local sysadmin if they have a mailserver that employees/students can use. – kristaps Aug 23 '18 at 12:13
0

If you are using G mail, you need to enable 2FA(2 Factor Authentication) and go to App passwords setting. Then you can generate app password, and you must put that password into Django settings.py like this:

#settings.py
SERVER_EMAIL = DEFAULT_FROM_EMAIL = EMAIL_HOST_USER = 'YOUR_GMAIL_ADDRESS'
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_PASSWORD = 'YOUR_APP_PASSWORD'

It worked for me :)
See this article for how to generate app password and use it for django:
https://kinsta.com/knowledgebase/free-smtp-server/
(You can skip step 4)