当前位置: 首页 > 知识库问答 >
问题:

Django电子邮件错误:提出errsocket.error:[Errno 111]连接拒绝[重复]

戎高爽
2023-03-14

我在很多地方看到有人问我这个问题,但到目前为止,没有一个解决方案对我有效,或者可能是我无法理解到底该做什么(新手特质)。如果可以的话,请帮忙。

电子邮件设置/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

从Django Python Shell发送测试电子邮件时收到错误:

首先,我运行sendmail命令-给了我Error1:django。果心例外情况。配置不当:

>>> from 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, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

为了克服错误1-我运行了以下命令

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

第二,我再次运行发送邮件-给出错误2:电子邮件不出去!插座错误:[Errno 111]连接被拒绝

>>> from 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

共有1个答案

东门令
2023-03-14

所有这些都是在我试图从普通python提示符发送电子邮件时发生的,该提示符被调用为:

(venv)[user@server django_project]$  python

电子邮件一直没发出去。事实上,他们必须从

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

这为我解决了问题。电子邮件发出得很好。所以我的电子邮件设置没有问题,我发送邮件的方式有问题。

 类似资料:
  • 问题内容: 我正在尝试将Redis用作我的使用Docker Compose的Django项目的Celery的代理。我无法弄清楚我到底做错了什么,但是尽管控制台日志消息告诉我Redis正在运行并接受连接(实际上,当我这样做时,我可以看到容器正在运行),但我仍然会收到有关拒绝连接的错误消息。我什至做到了 看到回应是。 这是my中的Celery设置: 这是my中的Redis容器设置: 我还记得将容器与我

  • 问题内容: 当我发表评论时,不要保存,崩溃(错误:[Errno 111]连接被拒绝),为什么? views.py models.py 管理员 问题答案: 为了进行调试,你可以使用以下命令设置本地smtpserver: 并相应地调整你的邮件设置:

  • 线程“main”org.springframework.web.client.resourceAccessException中的异常:“http://localhost:8081/footballershirt/footballershirts”的GET请求上的I/O错误:拒绝连接:连接;嵌套的异常是java.net.connectException:Connection:Connection a

  • Do you ever wonder how your E-mail address gets on so many spam mailing lists? One way spammers collect E-mail addresses is from web pages. To help combat this problem, you can make your E-mail addres

  • 我有smtp邮件,我正在发送webproject帐户的验证邮件。Webprject是使用codeigniter 3.0开发的。 我用gmail进行了测试,它工作得很好。现在我不得不用smtp邮件代替gmail。它似乎没有成功连接到smtp帐户。 收到这样的错误

  • 我们在JMeter远程测试中面临问题。Master被困在: 正在端口4445上等待可能的Shutdown/StopTestNow/Heapdump消息 当客户抛出时: 连接被拒绝到主机异常 我们正在运行如下大师: 但是在从属端测试完成状态被发送到其他一些IP地址: 仅供参考:这台机器上运行了docker,并且10.0.75.1与它相关联