This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author piers
Recipients piers
Date 2008-11-12.08:17:16
SpamBayes Score 4.0126265e-06
Marked as misclassified No
Message-id <1226477840.43.0.0037139980832.issue4302@psf.upfronthosting.co.za>
In-reply-to
Content
smtplib does not initialise the valriable 'sock' in the case where
'host' is NULL on instantiation of smtplib.SMTP.

Eg:

% python
Python 2.5.2 (r252:60911, Oct  5 2008, 19:29:17) 
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import smtplib
>>> client=smtplib.SMTP('')
>>> client.sendmail('from@home', 'to@home', 'test')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.5/smtplib.py", line 676, in sendmail
    if not (200 <= self.ehlo()[0] <= 299):
  File "/usr/lib/python2.5/smtplib.py", line 397, in ehlo
    self.putcmd("ehlo", name or self.local_hostname)
  File "/usr/lib/python2.5/smtplib.py", line 333, in putcmd
    self.send(str)
  File "/usr/lib/python2.5/smtplib.py", line 318, in send
    if self.sock:
AttributeError: SMTP instance has no attribute 'sock'
>>>

The fix is to add "self.sock = None" in __init__ if host is not set,
and then the behaviour is much more helpful:

% python
Python 2.5.2 (r252:60911, Oct  5 2008, 19:29:17) 
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import smtplib
>>> client=smtplib.SMTP('')
>>> client.sendmail('from@home', 'to@home', 'test')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.5/smtplib.py", line 678, in sendmail
    if not (200 <= self.ehlo()[0] <= 299):
  File "/usr/lib/python2.5/smtplib.py", line 399, in ehlo
    self.putcmd("ehlo", name or self.local_hostname)
  File "/usr/lib/python2.5/smtplib.py", line 335, in putcmd
    self.send(str)
  File "/usr/lib/python2.5/smtplib.py", line 327, in send
    raise SMTPServerDisconnected('please run connect() first')
smtplib.SMTPServerDisconnected: please run connect() first
>>>
History
Date User Action Args
2008-11-12 08:17:21pierssetrecipients: + piers
2008-11-12 08:17:20pierssetmessageid: <1226477840.43.0.0037139980832.issue4302@psf.upfronthosting.co.za>
2008-11-12 08:17:19pierslinkissue4302 messages
2008-11-12 08:17:17pierscreate