2

I was trying to send an email from my Django app using gmail. I added these email settings to settings.py

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

But it throws this name resolution error:

Traceback (most recent call last):
File "/usr/lib/python3.4/code.py", line 90, in runcode
  exec(code, self.locals)
File "<console>", line 1, in <module>
File "/usr/local/lib/python3.4/dist-packages/Django-1.8.7-py3.4.egg/django/core/mail/__init__.py", line 62, in send_mail
  return mail.send()
File "/usr/local/lib/python3.4/dist-packages/Django-1.8.7-py3.4.egg/django/core/mail/message.py", line 303, in send
  return self.get_connection(fail_silently).send_messages([self])
File "/usr/local/lib/python3.4/dist-packages/Django-1.8.7-py3.4.egg/django/core/mail/backends/smtp.py", line 100, in send_messages
  new_conn_created = self.open()
File "/usr/local/lib/python3.4/dist-packages/Django-1.8.7-py3.4.egg/django/core/mail/backends/smtp.py", line 58, in open
  self.connection = connection_class(self.host, self.port, **connection_params)
File "/usr/lib/python3.4/smtplib.py", line 242, in __init__
  (code, msg) = self.connect(host, port)
File "/usr/lib/python3.4/smtplib.py", line 321, in connect
  self.sock = self._get_socket(host, port, self.timeout)
File "/usr/lib/python3.4/smtplib.py", line 292, in _get_socket
  self.source_address)
File "/usr/lib/python3.4/socket.py", line 494, in create_connection
  for res in getaddrinfo(host, port, 0, SOCK_STREAM):
File "/usr/lib/python3.4/socket.py", line 533, in getaddrinfo
  for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name or service not known

Note: I am working behind a proxy.

In addition, I tried to connect to google.com through socket:

import socket
socket.gethostbyname('www.google.com')

It throws:

[Errno 11001] getaddrinfo failed
Yet
  • 94
  • 1
  • 7

1 Answers1

1
  1. enable pop3 in gmail.com
  2. create specific password for django application (http://support.google.com/accounts/bin/answer.py?hl=en&answer=185833)

Solutions here

Community
  • 1
  • 1
Dmitry Kalinin
  • 363
  • 2
  • 11
  • I've enabled both access to less secure apps and pop. But it is not working now too. May be the case is related to **working behind proxy**. – Yet Dec 27 '15 at 18:38