[GH-ISSUE #397] smtplib.SMTPServerDisconnected: Connection unexpectedly closed #299

Closed
opened 2026-02-25 23:41:57 +03:00 by kerem · 2 comments
Owner

Originally created by @Georege on GitHub (Jul 8, 2020).
Original GitHub issue: https://github.com/healthchecks/healthchecks/issues/397

errors:

Internal Server Error: /integrations/b77ad2ea-ec1f-4939-8e44-be4b292af7c5/test/
Traceback (most recent call last):
File "D:\Downloads\healthchecks.venv\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "D:\Downloads\healthchecks.venv\lib\site-packages\django\core\handlers\base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "D:\Downloads\healthchecks.venv\lib\site-packages\django\core\handlers\base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "D:\Downloads\healthchecks.venv\lib\site-packages\django\views\decorators\http.py", line 40, in inner
return func(request, *args, **kwargs)
File "D:\Downloads\healthchecks.venv\lib\site-packages\django\contrib\auth\decorators.py", line 21, in _wrapped_view
return view_func(request, *args, **kwargs)
File "D:\Downloads\healthchecks\hc\front\views.py", line 787, in send_test_notification
error = channel.transport.notify(dummy, channel.get_unsub_link())
File "D:\Downloads\healthchecks\hc\api\transports.py", line 88, in notify
emails.alert(self.channel.email_value, ctx, headers)
File "D:\Downloads\healthchecks\hc\lib\emails.py", line 61, in alert
send("alert", to, ctx, headers)
File "D:\Downloads\healthchecks\hc\lib\emails.py", line 37, in send
t.run()
File "D:\Downloads\healthchecks\hc\lib\emails.py", line 23, in run
msg.send()
File "D:\Downloads\healthchecks.venv\lib\site-packages\django\core\mail\message.py", line 276, in send
return self.get_connection(fail_silently).send_messages([self])
File "D:\Downloads\healthchecks.venv\lib\site-packages\django\core\mail\backends\smtp.py", line 102, in send_messages
new_conn_created = self.open()
File "D:\Downloads\healthchecks.venv\lib\site-packages\django\core\mail\backends\smtp.py", line 62, in open
self.connection = self.connection_class(self.host, self.port, **connection_params)
File "d:\anaconda3\Lib\smtplib.py", line 251, in init
(code, msg) = self.connect(host, port)
File "d:\anaconda3\Lib\smtplib.py", line 338, in connect
(code, msg) = self.getreply()
File "d:\anaconda3\Lib\smtplib.py", line 394, in getreply
raise SMTPServerDisconnected("Connection unexpectedly closed")
smtplib.SMTPServerDisconnected: Connection unexpectedly closed

my settings

local_settings.py:

EMAIL_HOST = "smtp.exmail.qq.com"
EMAIL_PORT = "465"
EMAIL_HOST_USER = "test@test.com"
EMAIL_HOST_PASSWORD = "12345"
EMAIL_USE_TLS = "True"

settings.py:

EMAIL_USE_TLS = envbool("EMAIL_USE_TLS", "True")

What methods did I try

  1. comment out EMAIL_USE_TLS in local_settings.py and settings.py
  2. local_settings.py add EMAIL_USE_SSL = "True"

then Sending Emails success

but i dont know why?

Originally created by @Georege on GitHub (Jul 8, 2020). Original GitHub issue: https://github.com/healthchecks/healthchecks/issues/397 ## errors: > Internal Server Error: /integrations/b77ad2ea-ec1f-4939-8e44-be4b292af7c5/test/ Traceback (most recent call last): File "D:\Downloads\healthchecks\.venv\lib\site-packages\django\core\handlers\exception.py", line 34, in inner response = get_response(request) File "D:\Downloads\healthchecks\.venv\lib\site-packages\django\core\handlers\base.py", line 115, in _get_response response = self.process_exception_by_middleware(e, request) File "D:\Downloads\healthchecks\.venv\lib\site-packages\django\core\handlers\base.py", line 113, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "D:\Downloads\healthchecks\.venv\lib\site-packages\django\views\decorators\http.py", line 40, in inner return func(request, *args, **kwargs) File "D:\Downloads\healthchecks\.venv\lib\site-packages\django\contrib\auth\decorators.py", line 21, in _wrapped_view return view_func(request, *args, **kwargs) File "D:\Downloads\healthchecks\hc\front\views.py", line 787, in send_test_notification error = channel.transport.notify(dummy, channel.get_unsub_link()) File "D:\Downloads\healthchecks\hc\api\transports.py", line 88, in notify emails.alert(self.channel.email_value, ctx, headers) File "D:\Downloads\healthchecks\hc\lib\emails.py", line 61, in alert send("alert", to, ctx, headers) File "D:\Downloads\healthchecks\hc\lib\emails.py", line 37, in send t.run() File "D:\Downloads\healthchecks\hc\lib\emails.py", line 23, in run msg.send() File "D:\Downloads\healthchecks\.venv\lib\site-packages\django\core\mail\message.py", line 276, in send return self.get_connection(fail_silently).send_messages([self]) File "D:\Downloads\healthchecks\.venv\lib\site-packages\django\core\mail\backends\smtp.py", line 102, in send_messages new_conn_created = self.open() File "D:\Downloads\healthchecks\.venv\lib\site-packages\django\core\mail\backends\smtp.py", line 62, in open self.connection = self.connection_class(self.host, self.port, **connection_params) File "d:\anaconda3\Lib\smtplib.py", line 251, in __init__ (code, msg) = self.connect(host, port) File "d:\anaconda3\Lib\smtplib.py", line 338, in connect (code, msg) = self.getreply() File "d:\anaconda3\Lib\smtplib.py", line 394, in getreply raise SMTPServerDisconnected("Connection unexpectedly closed") smtplib.SMTPServerDisconnected: Connection unexpectedly closed ## my settings > local_settings.py: EMAIL_HOST = "smtp.exmail.qq.com" EMAIL_PORT = "465" EMAIL_HOST_USER = "test@test.com" EMAIL_HOST_PASSWORD = "12345" EMAIL_USE_TLS = "True" > settings.py: EMAIL_USE_TLS = envbool("EMAIL_USE_TLS", "True") ## What methods did I try 1. comment out EMAIL_USE_TLS in local_settings.py and settings.py 2. local_settings.py add EMAIL_USE_SSL = "True" ## then Sending Emails success ## but i dont know why?
kerem closed this issue 2026-02-25 23:41:57 +03:00
Author
Owner

@cuu508 commented on GitHub (Jul 8, 2020):

From Django docs:

EMAIL_USE_TLS
Default: False
Whether to use a TLS (secure) connection when talking to the SMTP server. This is used for explicit TLS connections, generally on port 587. If you are experiencing hanging connections, see the implicit TLS setting EMAIL_USE_SSL.

EMAIL_USE_SSL
Default: False
Whether to use an implicit TLS (secure) connection when talking to the SMTP server. In most email documentation this type of TLS connection is referred to as SSL. It is generally used on port 465. If you are experiencing problems, see the explicit TLS setting EMAIL_USE_TLS.
Note that EMAIL_USE_TLS/EMAIL_USE_SSL are mutually exclusive, so only set one of those settings to True.

<!-- gh-comment-id:655524619 --> @cuu508 commented on GitHub (Jul 8, 2020): From [Django docs](https://docs.djangoproject.com/en/3.0/ref/settings/#std:setting-EMAIL_USE_TLS): > EMAIL_USE_TLS > Default: False > Whether to use a TLS (secure) connection when talking to the SMTP server. This is used for explicit TLS connections, **generally on port 587**. If you are experiencing hanging connections, see the implicit TLS setting EMAIL_USE_SSL. > EMAIL_USE_SSL > Default: False > Whether to use an implicit TLS (secure) connection when talking to the SMTP server. In most email documentation this type of TLS connection is referred to as SSL. **It is generally used on port 465.** If you are experiencing problems, see the explicit TLS setting EMAIL_USE_TLS. > Note that EMAIL_USE_TLS/EMAIL_USE_SSL are mutually exclusive, so only set one of those settings to True.
Author
Owner

@Georege commented on GitHub (Jul 9, 2020):

From Django docs:

EMAIL_USE_TLS
Default: False
Whether to use a TLS (secure) connection when talking to the SMTP server. This is used for explicit TLS connections, generally on port 587. If you are experiencing hanging connections, see the implicit TLS setting EMAIL_USE_SSL.

EMAIL_USE_SSL
Default: False
Whether to use an implicit TLS (secure) connection when talking to the SMTP server. In most email documentation this type of TLS connection is referred to as SSL. It is generally used on port 465. If you are experiencing problems, see the explicit TLS setting EMAIL_USE_TLS.
Note that EMAIL_USE_TLS/EMAIL_USE_SSL are mutually exclusive, so only set one of those settings to True.

tank you very much!

<!-- gh-comment-id:655829343 --> @Georege commented on GitHub (Jul 9, 2020): > From [Django docs](https://docs.djangoproject.com/en/3.0/ref/settings/#std:setting-EMAIL_USE_TLS): > > > EMAIL_USE_TLS > > Default: False > > Whether to use a TLS (secure) connection when talking to the SMTP server. This is used for explicit TLS connections, **generally on port 587**. If you are experiencing hanging connections, see the implicit TLS setting EMAIL_USE_SSL. > > > EMAIL_USE_SSL > > Default: False > > Whether to use an implicit TLS (secure) connection when talking to the SMTP server. In most email documentation this type of TLS connection is referred to as SSL. **It is generally used on port 465.** If you are experiencing problems, see the explicit TLS setting EMAIL_USE_TLS. > > Note that EMAIL_USE_TLS/EMAIL_USE_SSL are mutually exclusive, so only set one of those settings to True. tank you very much!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/healthchecks#299
No description provided.