python - Django Email Error: raise err socket.error: [Errno 111] Connection refused -


i saw question being asked @ number of places no solutions have worked me far, or may unable understand (newbie traits). please if can.

email settings/ settings.py:

email_backend = 'django.core.mail.backends.smtp.emailbackend' email_use_tls = true email_host_user = 'xyz@gmail.com' email_host_password = 'pwd' email_host = 'smtp.gmail.com' email_port = 587 

error receiving while sending test email django python shell:

first ran send mail command - gave me error1: django.core.exceptions.improperlyconfigured:

>>> django.core.mail import send_mail >>> send_mail('test', 'test', 'xyz@gmail.com', ['abc@hotmail.com'], fail_silently=false) traceback (most recent call last): file "<stdin>", line 1, in <module> file "/home/django_admin1/venv-tile-prod/lib/python2.7/site-  packages/django-1.8.2-py2.7.egg/django/core/mail/__init__.py", line 56, in send_mail fail_silently=fail_silently) file "/home/django_admin1/venv-tile-prod/lib/python2.7/site-packages/django-1.8.2-py2.7.egg/django/core/mail/__init__.py", line 37, in get_connection klass = import_string(backend or settings.email_backend) file "/home/django_admin1/venv-tile-prod/lib/python2.7/site-packages/django-1.8.2-py2.7.egg/django/conf/__init__.py", line 48, in __getattr__ self._setup(name) file "/home/django_admin1/venv-tile-prod/lib/python2.7/site-packages/django-1.8.2-py2.7.egg/django/conf/__init__.py", line 42, in _setup % (desc, environment_variable)) django.core.exceptions.improperlyconfigured: requested setting email_backend, settings not configured. must either define environment variable django_settings_module or call settings.configure() before accessing settings. 

to overcome error1- ran below commands

>>> django.conf import settings >>> settings.configure() 

secondly ran send mail again - gave error2: emails not going out! socket.error: [errno 111] connection refused

>>> django.core.mail import send_mail >>> send_mail('test', 'test', 'xyz@gmail.com', ['abc@hotmail.com'], fail_silently=false) traceback (most recent call last): file "<stdin>", line 1, in <module> file "/home/django_admin1/venv-tile-prod/lib/python2.7/site-packages/django-1.8.2-py2.7.egg/django/core/mail/__init__.py", line 62, in send_mail return mail.send() file "/home/django_admin1/venv-tile-prod/lib/python2.7/site-packages/django-1.8.2-py2.7.egg/django/core/mail/message.py", line 303, in send return self.get_connection(fail_silently).send_messages([self]) file "/home/django_admin1/venv-tile-prod/lib/python2.7/site-packages/django-1.8.2-py2.7.egg/django/core/mail/backends/smtp.py", line 100, in send_messages new_conn_created = self.open() file "/home/django_admin1/venv-tile-prod/lib/python2.7/site-packages/django-1.8.2-py2.7.egg/django/core/mail/backends/smtp.py", line 58, in open self.connection = connection_class(self.host, self.port, **connection_params) file "/usr/local/lib/python2.7/smtplib.py", line 251, in __init__ (code, msg) = self.connect(host, port) file "/usr/local/lib/python2.7/smtplib.py", line 311, in connect self.sock = self._get_socket(host, port, self.timeout) file "/usr/local/lib/python2.7/smtplib.py", line 286, in _get_socket return socket.create_connection((host, port), timeout) file "/usr/local/lib/python2.7/socket.py", line 571, in create_connection raise err socket.error: [errno 111] connection refused 

all while attempting send email normal python prompt invoked as:

(venv)[user@server django_project]$  python 

the emails never went. have run

(venv)[user@server django_project]$  python manage.py shell >>> django.core.mail import send_mail >>> send_mail('test', 'this test email', 'xyz@gmail.com', ['recipientemail@hotmail.com'], fail_silently=false) 

that resolved issue me. email went out perfectly. there no problem email setup, there problem in way sending it.


Comments

Popular posts from this blog

How to show in django cms breadcrumbs full path? -

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -