diff -r 49533a9fe322 Lib/smtplib.py --- a/Lib/smtplib.py Thu Sep 08 20:50:03 2016 -0700 +++ b/Lib/smtplib.py Fri Sep 09 12:36:18 2016 +0300 @@ -241,7 +241,6 @@ will be used. """ - self._host = host self.timeout = timeout self.esmtp_features = {} self.command_encoding = 'ascii' @@ -328,6 +327,7 @@ port = int(port) except ValueError: raise OSError("nonnumeric port") + self._host = host if not port: port = self.default_port if self.debuglevel > 0: diff -r 49533a9fe322 Lib/test/test_smtplib.py --- a/Lib/test/test_smtplib.py Thu Sep 08 20:50:03 2016 -0700 +++ b/Lib/test/test_smtplib.py Fri Sep 09 12:36:18 2016 +0300 @@ -149,6 +149,15 @@ re.MULTILINE) self.assertRegex(stderr.getvalue(), expected) + def test_explicit_connect(self): + mock_socket.reply_with(b"220 Hello world") + # create instance without arguments + smtp = smtplib.SMTP() + # .connect must set ._host since it is used by .starttls + smtp.connect(HOST, self.port) + self.assertEqual(smtp._host, HOST) + smtp.close() + # Test server thread using the specified SMTP server class def debugging_server(serv, serv_evt, client_evt):