smtplib STARTTLS problems

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tim Williams

    #1

    smtplib STARTTLS problems

    I have a working SMTP client that I need to add TLS capability to, I
    absolutely need the client to timeout within a specified time, but when I
    use the sock.timeout() line it freezes the reading of chars from SSLFakeFile
    used during TLS instead of timing out the client connection. I am
    working from my own hacked version of smtplib, but can demonstrate the
    problem using the standard module (Python 2.3.4). Can anyone suggest a
    workaround hack that I can impliment in my own version of smtplib ??

    Thanks in advance

    Working version =

    import smtplib as mx
    s=mx.SMTP('e32. co.us.ibm.com')
    s.set_debugleve l(1)
    s.ehlo('x')
    resp, null = s.starttls()
    if resp == 220:
    s.ehlo('x')
    s.mail('me@mydo main.com')
    s.quit()



    Non-Working version =

    import smtplib as mx
    s=mx.SMTP('e32. co.us.ibm.com')
    s.sock.settimeo ut(20)
    s.set_debugleve l(1)
    s.ehlo('x')
    resp, null = s.starttls()
    if resp == 220:
    s.ehlo('x')
    s.mail('me@mydo main.com')
    s.quit()

    Traceback (most recent call last):
    File "<interacti ve input>", line 1, in ?
    File "tls2.py", line 8, in ?
    print s.ehlo('x')
    File "C:\Python23\li b\smtplib.py", line 404, in ehlo
    (code,msg)=self .getreply()
    File "C:\Python23\li b\smtplib.py", line 356, in getreply
    line = self.file.readl ine()
    File "C:\Python23\li b\smtplib.py", line 160, in readline
    chr = self.sslobj.rea d(1)
    sslerror: The read operation timed out



Working...