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.
You have typo in your settings.py it should be
EMAIL_USE_TLS = True
not EMAIL_USE_TSL = True