1

i'm using django-registration in my project to sending email when user forgot password. But i got the error [Errno -2] Name or service not known. Below are my settings and traceback..

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

gaierror at /accounts/password_reset/
    [Errno -2] Name or service not known
    Request Method: POST
    Request URL:    http://localhost:8000/accounts/password_reset/
    Django Version: 1.10.5
    Exception Type: gaierror
    Exception Value:    
    [Errno -2] Name or service not known
    Exception Location: /usr/lib/python2.7/socket.py in create_connection, line 553
    Python Executable:  /usr/bin/python
    Python Version: 2.7.6
    Python Path:    
    ['/vagrant/ifoswork/ifoswork',
     '/usr/lib/python2.7',
     '/usr/lib/python2.7/plat-x86_64-linux-gnu',
     '/usr/lib/python2.7/lib-tk',
     '/usr/lib/python2.7/lib-old',
     '/usr/lib/python2.7/lib-dynload',
     '/usr/local/lib/python2.7/dist-packages',
     '/usr/lib/python2.7/dist-packages']
    Server time:    Thu, 5 Oct 2017 14:38:34 +0800
MunirohMansoor
  • 355
  • 1
  • 10
  • 19
  • did u set DEFAULT_FROM_EMAIL = EMAIL_HOST_USER – Amrit Oct 05 '17 at 06:53
  • @amrit i already put those line before this.. but it does not change anything. – MunirohMansoor Oct 05 '17 at 06:55
  • 2
    It would not. The issue here is for some reason it cannot resolve the address of the remote server. Are you sure its dns is properly configured (and it's not blocked out by some firewall)? – spectras Oct 05 '17 at 06:58

1 Answers1

2

When I got this error it was caused by the wrong information in the following fields:

EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'my@gmail.com'
EMAIL_HOST_PASSWORD = 'mypassword'
EMAIL_PORT = 587

Except I am not using gmail, however I did find the following information on Django 1.8 sending mail using gmail SMTP

Go to your Google Account settings, find Security -> Account permissions -> Access for less secure apps, enable this option.

Essentially the error "[Errno -2] Name or service not known" can not connect to the email server.

Robotichead
  • 148
  • 2
  • 10