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

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

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发送电子邮件。

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = '<username@gmail.com>'
EMAIL_HOST_PASSWORD = '<app_password>'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_USE_SSL = False

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

from django.conf import settings
from django.core.mail import send_mail

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

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

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

In [1]: from django.conf import settings

In [2]: from django.core.mail import send_mail

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, 
   ...:  recipient_list=[&#39;&lt;username@gmail.com&gt;&#39;])
---------------------------------------------------------------------------
SMTPNotSupportedError                     Traceback (most recent call last)
Cell In[3], line 1
----&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;])

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)
     84 if html_message:
     85     mail.attach_alternative(html_message, &quot;text/html&quot;)
---&gt; 87 return mail.send()

File C:\PATH\lib\site-packages\django\core\mail\message.py:298, in EmailMessage.send(self, fail_silently)
    294 if not self.recipients():
    295     # Don&#39;t bother creating the network connection if there&#39;s nobody to
    296     # send to.
    297     return 0
--&gt; 298 return self.get_connection(fail_silently).send_messages([self])

File C:\PATH\lib\site-packages\django\core\mail\backends\smtp.py:127, in EmailBackend.send_messages(self, email_messages)
    125     return 0
    126 with self._lock:
--&gt; 127     new_conn_created = self.open()
    128     if not self.connection or new_conn_created is None:
    129         # We failed silently on open().
    130         # Trying to send would be pointless.
    131         return 0

File C:\PATH\lib\site-packages\django\core\mail\backends\smtp.py:94, in EmailBackend.open(self)
     92         self.connection.starttls(context=self.ssl_context)
     93     if self.username and self.password:
---&gt; 94         self.connection.login(self.username, self.password)
     95     return True
     96 except OSError:

File C:\PATH\lib\smtplib.py:716, in SMTP.login(self, user, password, initial_response_ok)
    714 self.ehlo_or_helo_if_needed()
    715 if not self.has_extn(&quot;auth&quot;):
--&gt; 716     raise SMTPNotSupportedError(
    717         &quot;SMTP AUTH extension not supported by server.&quot;)
    719 # Authentication methods the server claims to support
    720 advertised_authlist = self.esmtp_features[&quot;auth&quot;].split()

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:

确定