1

我正在使用 Django 的电子邮件后端发送帐户验证电子邮件。这是我的设置的样子:

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.zoho.in'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'someone@example.com'
DEFAULT_FROM_EMAIL = 'someone@example.com'
EMAIL_HOST_PASSWORD = 'somepassword'
EMAIL_USE_TLS = True

直到几个小时前它突然停止工作时,此配置都可以正常工作,并引发此错误:

Traceback (most recent call last):
  File "/home/ubuntu/venv/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/home/ubuntu/venv/lib/python3.8/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/ubuntu/venv/lib/python3.8/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "/home/ubuntu/venv/lib/python3.8/site-packages/rest_framework/viewsets.py", line 125, in view
    return self.dispatch(request, *args, **kwargs)
  File "/home/ubuntu/venv/lib/python3.8/site-packages/rest_framework/views.py", line 509, in dispatch
    response = self.handle_exception(exc)
  File "/home/ubuntu/venv/lib/python3.8/site-packages/rest_framework/views.py", line 469, in handle_exception
    self.raise_uncaught_exception(exc)
  File "/home/ubuntu/venv/lib/python3.8/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception
    raise exc
  File "/home/ubuntu/venv/lib/python3.8/site-packages/rest_framework/views.py", line 506, in dispatch
    response = handler(request, *args, **kwargs)
  File "/home/ubuntu/venv/lib/python3.8/site-packages/rest_framework/mixins.py", line 19, in create
    self.perform_create(serializer)
  File "/home/ubuntu/venv/lib/python3.8/site-packages/djoser/views.py", line 144, in perform_create
    settings.EMAIL.activation(self.request, context).send(to)
  File "/home/ubuntu/venv/lib/python3.8/site-packages/templated_mail/mail.py", line 78, in send
    super(BaseEmailMessage, self).send(*args, **kwargs)
  File "/home/ubuntu/venv/lib/python3.8/site-packages/django/core/mail/message.py", line 284, in send
    return self.get_connection(fail_silently).send_messages([self])
  File "/home/ubuntu/venv/lib/python3.8/site-packages/django/core/mail/backends/smtp.py", line 102, in send_messages
    new_conn_created = self.open()
  File "/home/ubuntu/venv/lib/python3.8/site-packages/django/core/mail/backends/smtp.py", line 69, in open
    self.connection.login(self.username, self.password)
  File "/usr/lib/python3.8/smtplib.py", line 734, in login
    raise last_exception
  File "/usr/lib/python3.8/smtplib.py", line 723, in login
    (code, resp) = self.auth(
  File "/usr/lib/python3.8/smtplib.py", line 646, in auth
    raise SMTPAuthenticationError(code, resp)
smtplib.SMTPAuthenticationError: (535, b'Authentication Failed')

我不确定是什么触发了错误,但现在它也不适用于其他主机帐户。我没有更改任何内容,我的 Zoho 帐户的 2FA 也没有激活。它停止工作的原因可能是什么?

4

1 回答 1

-1

只是改变了这一行

EMAIL_HOST = 'smtp.zoho.in'

到这条线

EMAIL_HOST = 'smtp.zoho.com'

我仍然无法解决您的问题,这意味着您已在您的 zoho 帐户中打开了两因素身份验证。因此,请将其关闭或仅在 zoho 帐户中生成应用程序生成的密码并在您的代码中使用它。

于 2021-05-30T15:57:18.323 回答