title: Error smtplib in python
body: <p>i've a python script, run on a raspeberry pi that monitoring my server room and periodically send me an e-mail and make other stuff.
  First time script is running it send a notification and works fine, then wait for a time (5 or 30 minutues) depending if an alarm is triggered, so i've write a for loop to wait. when the loop is finish, script make a call of the function for sending e-mail and python return an error.
  Could someone help me ?
  i test it also on debian 7.7.0 box and i've the same error.
  Below a sample script and the error.
  Thanks in advance.
  Dom.</p>
  
  <pre><code>File "/usr/lib/python2.7/smtplib.py", line 361, in getreply
  raise SMTPServerDisconnected("Connection unexpectedly closed")
  smtplib.SMTPServerDisconnected: Connection unexpectedly closed
  
  # Import
  from time import sleep
  import time
  import smtplib
  import sys
  import string
  smtp_server = "10.0.0.4" # mail server address
  mail_from = "server@domain.com" 
  mail_to = "user@gmail.com" 
  mail_subj = "Server room notify" 
  
  server = smtplib.SMTP(smtp_server)
  valore = 24 # value for the funtion
  
  def SendAlertEmail(t_value):
      log_t = time.strftime("%d/%m/%A %H:%M:%S ")
      Text = string.join("Server room notify \n " + str(log_t) + str(t_value))
      Body_email = string.join((
         "From: %s" % mail_from,
         "To: %s" % mail_to,
         "Subject: %s" % mail_subj,
         "",
         Text
         ), "\r\n")
      server.sendmail(mail_from,mail_to,Body_email)
      return
  
  SendAlertEmail(valore) # calling from here works fine
  for i in range(0,500):
      sleep(1)
      print(str(i))
  
  SendAlertEmail(valore) # after 500 secs goes in error. Test on debian 7.7.0 python 2.7.3 gcc 4.7.2
  </code></pre>