msg335511 - (view) |
Author: lidayan (lidayan) * |
Date: 2019-02-14 08:45 |
SSL encrypted socket on SMTPHandler error
Traceback (most recent call last):
File "/usr/local/Cellar/python/3.7.2_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/logging/handlers.py", line 1008, in emit
smtp = smtplib.SMTP(self.mailhost, port, timeout=self.timeout)
File "/usr/local/Cellar/python/3.7.2_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/smtplib.py", line 251, in __init__
(code, msg) = self.connect(host, port)
File "/usr/local/Cellar/python/3.7.2_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/smtplib.py", line 338, in connect
(code, msg) = self.getreply()
File "/usr/local/Cellar/python/3.7.2_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/smtplib.py", line 391, in getreply
+ str(e))
smtplib.SMTPServerDisconnected: Connection unexpectedly closed: timed out
|
msg335512 - (view) |
Author: Stéphane Wirtel (matrixise) * |
Date: 2019-02-14 08:46 |
You have a timeout, maybe you have an issue with your SMTP server. But in this case, it's not an issue with Python.
|
msg335520 - (view) |
Author: Emmanuel Arias (eamanu) * |
Date: 2019-02-14 11:51 |
hmmm do you have some code to reproduce it?
|
msg335522 - (view) |
Author: Stéphane Wirtel (matrixise) * |
Date: 2019-02-14 12:10 |
I re-open this issue because after the change of the subject, maybe there is an issue with the code of logging.handler.SMTPHandler + TLS.
|
msg335523 - (view) |
Author: Stéphane Wirtel (matrixise) * |
Date: 2019-02-14 12:20 |
@lidayan
I have checked the code of your PR, and I think there is an issue with your code.
1. When you specify the secure flag to the SMTPHandler, it's because you will start the TLS connection if the SMTP server supports the STARTTLS. Firstly in plaintext mode and if STARTTLS is supported then we move to the TLS encryption.
2. If you use SSL + SMTP, it's not the same behavior because you support that your SMTP server will support a socket + ssl.
For my part, I suggest you the creation of a SMTPSSLHandler and use the SMTP_SSL class.
|
msg335524 - (view) |
Author: Stéphane Wirtel (matrixise) * |
Date: 2019-02-14 12:26 |
Here is my suggestion
class SMTPSSLHander(SMTPHandler):
def emit(self, record):
"""
Emit a record.
Format the record and send it to the specified addressees.
"""
try:
import smtplib
from email.message import EmailMessage
import email.utils
port = self.mailport
if not port:
port = smtplib.SMTP_SSL_PORT
keyfile = self.secure[0] if len(self.secure) > 0 else None
certfile = self.secure[1] if len(self.secure) > 1 else None
smtp = smtplib.SMTP_SSL(self.mailhost, port, timeout=self.timeout,
keyfile=keyfile, certfile=certfile)
if self.username:
smtp.login(self.username, self.password)
msg = EmailMessage()
msg['From'] = self.fromaddr
msg['To'] = ','.join(self.toaddrs)
msg['Subject'] = self.getSubject(record)
msg['Date'] = email.utils.localtime()
msg.set_content(self.format(record))
smtp.send_message(msg)
smtp.quit()
except Exception:
self.handleError(record)
|
msg335525 - (view) |
Author: Stéphane Wirtel (matrixise) * |
Date: 2019-02-14 12:28 |
I propose to create a SMTPSSLHandler class and submit a PR.
|
msg335527 - (view) |
Author: Julien Palard (mdk) * |
Date: 2019-02-14 12:35 |
lidayan If I understand correctly, you're trying to connect to an SMTP server that does *not* support STARTTLS, only implicit TLS on port 465?
|
msg335528 - (view) |
Author: Julien Palard (mdk) * |
Date: 2019-02-14 12:43 |
@lidayan, if you're trying implicit TLS, have you tried giving a username an an empty tuple to the secure parameter?
It looks like the empty tuple means "implicit TLS", see the docstring https://github.com/python/cpython/blob/7fea5ad9f081247927bc851605f3a6269cbcd84d/Lib/logging/handlers.py#L959
|
msg335531 - (view) |
Author: Julien Palard (mdk) * |
Date: 2019-02-14 13:28 |
lidayan (Ignore my latest comment I was reading your implementation, not the actual one...).
|
msg336084 - (view) |
Author: Stéphane Wirtel (matrixise) * |
Date: 2019-02-20 13:04 |
@lidayan
I think it's a misuse of the logging.handlers.SMTPHandler class.
|
msg336173 - (view) |
Author: lidayan (lidayan) * |
Date: 2019-02-21 02:08 |
OK, I got it.
> 在 2019年2月14日,16:46,Stéphane Wirtel <report@bugs.python.org> 写道:
>
>
> Stéphane Wirtel <stephane@wirtel.be> added the comment:
>
> You have a timeout, maybe you have an issue with your SMTP server. But in this case, it's not an issue with Python.
>
> ----------
> nosy: +matrixise
> resolution: -> rejected
> stage: -> resolved
> status: open -> closed
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <https://bugs.python.org/issue35995>
> _______________________________________
>
|
msg336178 - (view) |
Author: lidayan (lidayan) * |
Date: 2019-02-21 03:04 |
And I have changed the code, please help to review, thanks
> 在 2019年2月21日,10:08,李大炎 <840286247@qq.com> 写道:
>
> OK, I got it.
>
>
>> 在 2019年2月14日,16:46,Stéphane Wirtel <report@bugs.python.org> 写道:
>>
>>
>> Stéphane Wirtel <stephane@wirtel.be> added the comment:
>>
>> You have a timeout, maybe you have an issue with your SMTP server. But in this case, it's not an issue with Python.
>>
>> ----------
>> nosy: +matrixise
>> resolution: -> rejected
>> stage: -> resolved
>> status: open -> closed
>>
>> _______________________________________
>> Python tracker <report@bugs.python.org>
>> <https://bugs.python.org/issue35995>
>> _______________________________________
>>
>
|
msg336179 - (view) |
Author: lidayan (lidayan) * |
Date: 2019-02-21 03:20 |
1. When specify the secure flag to the SMTPHandler, means start TLS connection.
2. if SMTP Server not support plaintext mode, but firstly in plaintext mode it is a error
|
msg336242 - (view) |
Author: Vinay Sajip (vinay.sajip) * |
Date: 2019-02-21 17:35 |
The existing implementation supports doing an SSL handshake using STARTTLS, which provides encryption for the actual email traffic. You are asking, it seems, to support a server that only listens on an already encrypted connection, and doesn't use STARTTLS. That would, in my book, be an *enhancement request* and not a bug. Your PR has removed the STARTTLS support - what is supposed to happen when connecting to a server that listens unencrypted and expects to use STARTTLS to initiate encypted traffic?
|
msg346054 - (view) |
Author: Vinay Sajip (vinay.sajip) * |
Date: 2019-06-19 14:47 |
Closing, as no answer has been received to the last question.
|
|
Date |
User |
Action |
Args |
2022-04-11 14:59:11 | admin | set | github: 80176 |
2019-06-19 14:47:45 | vinay.sajip | set | status: open -> closed resolution: not a bug messages:
+ msg346054
|
2019-02-21 17:35:15 | vinay.sajip | set | messages:
+ msg336242 |
2019-02-21 03:20:43 | lidayan | set | messages:
+ msg336179 |
2019-02-21 03:04:15 | lidayan | set | messages:
+ msg336178 |
2019-02-21 02:08:56 | lidayan | set | messages:
+ msg336173 title: use SSL encrypted socket on logging.handlers.SMTPHandler -> logging.handlers.SMTPHandler |
2019-02-20 13:04:54 | matrixise | set | messages:
+ msg336084 |
2019-02-14 13:28:18 | mdk | set | messages:
+ msg335531 |
2019-02-14 12:43:20 | mdk | set | messages:
+ msg335528 |
2019-02-14 12:35:39 | mdk | set | nosy:
+ mdk messages:
+ msg335527
|
2019-02-14 12:28:04 | matrixise | set | messages:
+ msg335525 |
2019-02-14 12:26:24 | matrixise | set | messages:
+ msg335524 |
2019-02-14 12:22:44 | xtreak | set | nosy:
+ vinay.sajip
|
2019-02-14 12:20:27 | matrixise | set | messages:
+ msg335523 |
2019-02-14 12:10:24 | matrixise | set | status: closed -> open resolution: rejected -> (no value) messages:
+ msg335522
|
2019-02-14 11:51:09 | eamanu | set | nosy:
+ eamanu messages:
+ msg335520
|
2019-02-14 11:17:21 | lidayan | set | pull_requests:
+ pull_request11888 |
2019-02-14 10:22:44 | lidayan | set | pull_requests:
+ pull_request11886 |
2019-02-14 08:47:46 | lidayan | set | title: logging.handlers.SMTPHandler -> use SSL encrypted socket on logging.handlers.SMTPHandler |
2019-02-14 08:46:58 | matrixise | set | status: open -> closed
nosy:
+ matrixise messages:
+ msg335512
resolution: rejected stage: resolved |
2019-02-14 08:45:46 | lidayan | create | |