“SMTPNotSupportedError: SMTP服务器不支持SMTP AUTH扩展” – 错误

huangapple go评论76阅读模式
英文:

DJANGO - "SMTPNotSupportedError: SMTP AUTH extension not supported by server" - error

问题

我有一个应用程序,我正在使用Django进行电子邮件发送测试。Django项目仍在开发中,我正在使用默认的sqlite3作为数据库。我已经在我的app_name/settings.py文件中配置了EMAIL_BACKEND、EMAIL_HOST、EMAIL_HOST_USER、EMAIL_HOST_PASSWORD、EMAIL_PORT、EMAIL_USE_TSL和EMAIL_USE_SSL字段。我尝试使用默认的个人gmail.com发送电子邮件。

  1. EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
  2. EMAIL_HOST = 'smtp.gmail.com'
  3. EMAIL_HOST_USER = '<username@gmail.com>'
  4. EMAIL_HOST_PASSWORD = '<app_password>'
  5. EMAIL_PORT = 587
  6. EMAIL_USE_TLS = True
  7. EMAIL_USE_SSL = False

我尝试在Python的PowerShell中像这样发送电子邮件:

  1. from django.conf import settings
  2. from django.core.mail import send_mail
  3. send_mail(subject='Add an eye-catching subject', message='Write an amazing message', from_email=settings.EMAIL_HOST_USER, fail_silently=False, recipient_list=['<username@gmail.com>'])

但是我尝试发送电子邮件时出现了SMTPNotSupportedError错误,错误信息为"SMTP AUTH extension not supported by server."。

英文:

I have an app where I'm testing email sending with django. The django project is still and development and I'm using the default sqlite3 as database. I have configured the EMAIL_BACKEND, EMAIL_HOST, EMAIL_HOST_USER, EMAIL_HOST_PASSWORD, EMAIL_PORT, EMAIL_USE_TSL and EMAIL_USE_SSLfields in my app_name/settings.py. I am trying to send the email with a default personal gmail.com

  1. EMAIL_BACKEND = &#39;django.core.mail.backends.smtp.EmailBackend&#39;
  2. EMAIL_HOST = &#39;smtp.gmail.com&#39;
  3. EMAIL_HOST_USER = &#39;&lt;username@gmail.com&gt;&#39;
  4. EMAIL_HOST_PASSWORD = &#39;&lt;app_password&gt;&#39;
  5. EMAIL_PORT = 587
  6. EMAIL_USE_TSL = True
  7. EMAIL_USE_SSL = False

And I'm trying to send the email in the python powershell like this:

  1. In [1]: from django.conf import settings
  2. In [2]: from django.core.mail import send_mail
  3. In [3]: send_mail(subject=&#39;Add an eye-catching subject&#39;, message=&#39;Write an amazing message&#39;, from_email=settings.EMAIL_HOST_USER, fail_silently=False,
  4. ...: recipient_list=[&#39;&lt;username@gmail.com&gt;&#39;])
  5. ---------------------------------------------------------------------------
  6. SMTPNotSupportedError Traceback (most recent call last)
  7. Cell In[3], line 1
  8. ----&gt; 1 send_mail(subject=&#39;Add an eye-catching subject&#39;, message=&#39;Write an amazing message&#39;, from_email=settings.EMAIL_HOST_USER, fail_silently=False, recipient_list=[&#39;&lt;username@gmail.com&gt;&#39;])
  9. File C:\PATH\lib\site-packages\django\core\mail\__init__.py:87, in send_mail(subject, message, from_email, recipient_list, fail_silently, auth_user, auth_password, connection, html_message)
  10. 84 if html_message:
  11. 85 mail.attach_alternative(html_message, &quot;text/html&quot;)
  12. ---&gt; 87 return mail.send()
  13. File C:\PATH\lib\site-packages\django\core\mail\message.py:298, in EmailMessage.send(self, fail_silently)
  14. 294 if not self.recipients():
  15. 295 # Don&#39;t bother creating the network connection if there&#39;s nobody to
  16. 296 # send to.
  17. 297 return 0
  18. --&gt; 298 return self.get_connection(fail_silently).send_messages([self])
  19. File C:\PATH\lib\site-packages\django\core\mail\backends\smtp.py:127, in EmailBackend.send_messages(self, email_messages)
  20. 125 return 0
  21. 126 with self._lock:
  22. --&gt; 127 new_conn_created = self.open()
  23. 128 if not self.connection or new_conn_created is None:
  24. 129 # We failed silently on open().
  25. 130 # Trying to send would be pointless.
  26. 131 return 0
  27. File C:\PATH\lib\site-packages\django\core\mail\backends\smtp.py:94, in EmailBackend.open(self)
  28. 92 self.connection.starttls(context=self.ssl_context)
  29. 93 if self.username and self.password:
  30. ---&gt; 94 self.connection.login(self.username, self.password)
  31. 95 return True
  32. 96 except OSError:
  33. File C:\PATH\lib\smtplib.py:716, in SMTP.login(self, user, password, initial_response_ok)
  34. 714 self.ehlo_or_helo_if_needed()
  35. 715 if not self.has_extn(&quot;auth&quot;):
  36. --&gt; 716 raise SMTPNotSupportedError(
  37. 717 &quot;SMTP AUTH extension not supported by server.&quot;)
  38. 719 # Authentication methods the server claims to support
  39. 720 advertised_authlist = self.esmtp_features[&quot;auth&quot;].split()
  40. SMTPNotSupportedError: SMTP AUTH extension not supported by server.

答案1

得分: 0

你的settings.py文件中有拼写错误,应该是

EMAIL_USE_TLS = True

而不是

EMAIL_USE_TSL = True

英文:

You have typo in your settings.py it should be

EMAIL_USE_TLS = True not EMAIL_USE_TSL = True

huangapple
  • 本文由 发表于 2023年7月27日 18:23:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/76778784.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定