连接被拒绝错误:当尝试通过django发送电子邮件时

3b6akqbq  于 2023-01-03  发布在  Go
关注(0)|答案(1)|浏览(146)

我有一个简单的django应用程序。所以我试着测试我的发送邮件功能。我已经允许我的邮件被第三方应用程序使用。一切看起来都很好,但一次又一次我捕捉到同样的错误

settings.configure()

def send_email(email=None):
    send_mail(
        'Subject here',
        'Here is the message.',
        from_email=settings.DEFAULT_FROM_EMAIL,
        recipient_list=['georgdavidov2@gmail.com'],
        fail_silently=False
    )

所以我收到一条错误消息

Traceback (most recent call last):
      File "C:\DEV\FindHero\backend\find_hero\services\send_email.py", line 17, in <module>
        send_email()
      File "C:\DEV\FindHero\backend\find_hero\services\send_email.py", line 8, in send_email
        send_mail(
      File "C:\Program Files\Python311\Lib\site-packages\django\core\mail\__init__.py", line 87, in send_mail
        return mail.send()
               ^^^^^^^^^^^
      File "C:\Program Files\Python311\Lib\site-packages\django\core\mail\message.py", line 298, in send
        return self.get_connection(fail_silently).send_messages([self])
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Program Files\Python311\Lib\site-packages\django\core\mail\backends\smtp.py", line 124, in send_messages
        new_conn_created = self.open()
                           ^^^^^^^^^^^
      File "C:\Program Files\Python311\Lib\site-packages\django\core\mail\backends\smtp.py", line 80, in open
        self.connection = self.connection_class(
                          ^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Program Files\Python311\Lib\smtplib.py", line 255, in __init__
        (code, msg) = self.connect(host, port)
                      ^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Program Files\Python311\Lib\smtplib.py", line 341, in connect
        self.sock = self._get_socket(host, port, self.timeout)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Program Files\Python311\Lib\smtplib.py", line 312, in _get_socket
        return socket.create_connection((host, port), timeout,
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Program Files\Python311\Lib\socket.py", line 850, in create_connection
        raise exceptions[0]
      File "C:\Program Files\Python311\Lib\socket.py", line 835, in create_connection
        sock.connect(sa)
    ConnectionRefusedError: [WinError 10061]

Hee是我的django设置:

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.yandex.ru'
EMAIL_PORT = 465
EMAIL_HOST_USER = "emaily@yandex.ru"
EMAIL_HOST_PASSWORD = "password"
EMAIL_USE_TLS = True
EMAIL_USE_SSL = False
SERVER_EMAIL = EMAIL_HOST_USER
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER

然后我就在那里使用send_mail()调用我的func,并尝试在python manage.py shell中不使用settings.configure()调用它

UPDim使用由yandex创建的特殊密码并使用双因素身份验证。

tjvv9vkg

tjvv9vkg1#

您应在电子邮件中激活两步验证,并使用应用程序密码而非常规电子邮件密码。

相关问题