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

    Access your files securely from anywhere

        Zoho Developer Community




                                  Zoho Desk Resources

                                  • Desk Community Learning Series


                                  • Digest


                                  • Functions


                                  • Meetups


                                  • Kbase


                                  • Resources


                                  • Glossary


                                  • Desk Marketplace


                                  • MVP Corner


                                  • Word of the Day



                                      Zoho Marketing Automation
                                              • Sticky Posts

                                              • 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
                                              • 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
                                              • 📣 📣 ZUG Meetups India - Explore Hybrid Workspaces using Zoho Workplace - Meet and Learn! 🧑🏽‍💻🧑🏽‍💻

                                                We are excited to announce the User Community initiative to meet you all in person and help you explore the need of the hour - Hybrid Workspaces using Zoho Workplace. We aim to help you to setup your Digital Workplace effectively so that your employees
                                              • Announcing Zoho Mail - Inactive user Policy

                                                Dear Zoho Mail users, Thanks to all of you for your continuous support.  We have recently started implementing the Inactive User Policy, for Zoho Mail.  A user is considered as inactive, if the user has not logged in to the Zoho mail account for a period of more than 120 days. The login through POP, IMAP and Active Sync are all taken into account for tracking the period of inactivity.  Whoever received the communication need not panic, as we have just communicated our policy to all the users.  To


                                              Manage your brands on social media



                                                    Zoho TeamInbox Resources

                                                      Zoho DataPrep Resources



                                                        Zoho CRM Plus Resources

                                                          Zoho Books Resources


                                                            Zoho Subscriptions Resources

                                                              Zoho Projects Resources


                                                                Zoho Sprints Resources


                                                                  Qntrl Resources


                                                                    Zoho Creator Resources



                                                                        Zoho Campaigns Resources


                                                                          Zoho CRM Resources

                                                                          • CRM Community Learning Series

                                                                            CRM Community Learning Series


                                                                          • Kaizen

                                                                            Kaizen

                                                                          • Functions

                                                                            Functions

                                                                          • Meetups

                                                                            Meetups

                                                                          • Kbase

                                                                            Kbase

                                                                          • Resources

                                                                            Resources

                                                                          • Digest

                                                                            Digest

                                                                          • CRM Marketplace

                                                                            CRM Marketplace

                                                                          • MVP Corner

                                                                            MVP Corner





                                                                              Design. Discuss. Deliver.

                                                                              Create visually engaging stories with Zoho Show.

                                                                              Get Started Now