英文:
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 = '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_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='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 Traceback (most recent call last)
Cell In[3], line 1
----> 1 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>'])
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, "text/html")
---> 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't bother creating the network connection if there's nobody to
296 # send to.
297 return 0
--> 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:
--> 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:
---> 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("auth"):
--> 716 raise SMTPNotSupportedError(
717 "SMTP AUTH extension not supported by server.")
719 # Authentication methods the server claims to support
720 advertised_authlist = self.esmtp_features["auth"].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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论