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
    >>>

      • Sticky Posts

      • Pocket from Mozilla is closing shop. Don’t lose your favorites . Move them to Zoho Mail Bookmarks now! 📥🔖

        The end of Pocket shouldn't mean the end of your important links and content. Easily import them into Zoho Mail's Bookmarks and continue right where you left off. You can bring over your entire Saves, Collections, and tags just the way they are. Bookmarks
      • Zoho Mail POP & IMAP Server Details

        Hello all! We have been receiving a number of requests regarding the errors while configuring or using Zoho Mail account in POP/ IMAP clients. The server details vary based on your account type and the Datacenter in which your account is setup. Ensure
      • Workplace - Zoholics Europe Customer Awards

        Dear Zoho Mail Community! 📣 We're excited to announce that at this year's Zoholics events across Europe, we're holding customer awards for the first time ever! Workplace - Zoholics Europe Customer Awards This is your chance to shout about the amazing
      • Important update on Group Management | Zoho Mail

        Dear Zoho Mail Community, This post is to inform you all of the following updates on the Group Management in Zoho Mail. Group Member Addition: If a group member is added to an organization group in a Zoho Application, the member will be automatically
      • Mastering email etiquette and best practices to follow in Zoho Mail

        Hello Zoho Mail Community, We’re thrilled to invite you all to our upcoming webinar: Mastering email etiquette and best practices to follow in Zoho Mail. Join our live webinar for expert etiquette tips to enhance your professionalism and elevate your