Python smtplib hangs on send command

Python smtplib hangs on send command

Hi all,

Has anyone else had a problem with pythin smtp lib not sending mail?  if anyone knows how to get around my issue I'd really appreciate some help if anyone can do so.

I'm an inexperienced user, so this might be a really simple issue, apologies if that is the case.

The same script run below for a tls connection works using gmail, so I know it works in some contexts.

Python logs in and authenticates fine, but will not send with either startls on 587 or ssl on 465.  Behaviour is the same on both ports.

Connection and authentication occurs properly, but command hangs (and then presumably times out) resulting in an "Connection unexpectedly closed" Error.

have been debugging using python in terminal, command set and returns shown, python tries for a couple of minutes before spitting the dummy, so wonder if it's a problem with the way smtplib and the server are talking.

Simple but needed info:
-the login to zoho and the "from" mail field are the same as per zoho requirements.
-I've manually crossed out IP addresses and my computer name, not sure what the etiquette is on them, so have replaced this info with X's
-I've run this with username and password directly passed to the relevant methods, rather than storing them in variables.  It didn't make a difference.
  1. >>> import smtplib
    >>>
    >>> ms = smtplib.SMTP("smtp.zoho.com",587)
    >>>
    >>> ms.ehlo()
    (250, 'mx.zohomail.com Hello XXXX.local (XXX-XXX-XXX-XX.iinet.net.au (XXX-XXX-XXX-XX))\nSTARTTLS\nSIZE 25000000')
    >>>
    >>> ms.starttls()
    (220, 'Ready to start TLS.')
    >>>
    >>> #print user,pwd,mail
    ...
    >>> ms.login(user,pwd)
    (235, 'Authentication Successful')
    >>>
    >>> ms.sendmail(user,to,mail)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py", line 743, in sendmail
        (code, resp) = self.data(msg)
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py", line 511, in data
        (code, msg) = self.getreply()
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py", line 368, in getreply
        raise SMTPServerDisconnected("Connection unexpectedly closed")
    smtplib.SMTPServerDisconnected: Connection unexpectedly closed
    >>>


  1. >>> import smtplib
    >>>
    >>> ms = smtplib.SMTP_SSL("smtp.zoho.com",465)
    >>>
    >>> ms.ehlo()
    (250, 'mx.zohomail.com Hello XXXX.local (XXX-XXX-XXX-XX.iinet.net.au (XXX.XXX.XXX.XX))\nAUTH LOGIN PLAIN\nSIZE 25000000')
    >>>
    >>> #ms.starttls()
    ...
    >>> #print user,pwd,mail
    ...
    >>> ms.login(user,pwd)
    (235, 'Authentication Successful')
    >>>
    >>> ms.sendmail(user,to,mail)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py", line 743, in sendmail
        (code, resp) = self.data(msg)
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py", line 511, in data
        (code, msg) = self.getreply()
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py", line 368, in getreply
        raise SMTPServerDisconnected("Connection unexpectedly closed")
    smtplib.SMTPServerDisconnected: Connection unexpectedly closed
    >>>