Connection unexpectedly closed Error while using SMTPLib

Connection unexpectedly closed Error while using SMTPLib

This is the code fragment that I am trying to use

  1. import smtplib
  2. import sys
  3. sender = 'username@datamattic.com'
  4. receivers = ['uname@gmail.com','username@datamattic.com']
  5. message = """From: From Person <from@fromdomain.com>
    To: To Person <to@todomain.com>
    Subject: SMTP e-mail test

    This is a test e-mail message.
    """




  6. try:
  7.     smtpObj = smtplib.SMTP_SSL('smtp.zoho.com',465)
  8.     smtpObj.login('username@datamattic.com','SamplePassword')
  9.     smtpObj.sendmail(sender, receivers, message)
  10.     print "Successfully sent email"
  11.     smtpObj.quit()
  12. except Exception, exc:
  13.     sys.exit( "mail failed; %s" % str(exc) ) # give a error message

Upon execution, it always fails with the rror message "Connection unexpectedly closed". Am I missing something? I was earlier getting authentication failure messages following which I disabled two factor authentication on my account.