title: Python application using office365 exchange server timing out
body: <p>I have a Python program that collects about 11K entries from a CORBA database, then uses those entries to parse through about 1,0000 Mb of text files.  This entire process normally takes 5-7 minutes.  I log into the Exchange365 server before this starts (so that any unusual events can be emailed to the administrator) and then try to email the results to the 'normal' recipients.  That last email is failing and the root cause seems to be that I am getting logged off of the Exchange server.</p>
  
  <p>Adding a 'dummy' email about half way through the processing seems to eliminate the timeout, but I'd like to find a more programatic way to accomplish this.  Following is a code snippet where I enable the email:</p>
  
  <pre><code>import smtp
  import time
  
  pretty_localtime = time.asctime()
  smtpserver = smtplib.SMTP("smtp.office365.com",587)
  smtpserver.ehlo()
  smtpserver.starttls()
  smtpserver.ehlo()
  #
  try:
      smtpserver.login(office365_user,office365_pwd)
  except:
      msg = ("%s --- FATAL ERROR:  Couldn't log into SMTP server.")%pretty_localtime
      log_file.write("%s \n"%msg)
      print msg
      sys.exit()
  </code></pre>
  
  <p>Has anyone worked through this problem?</p>
  
  <p><strong>***edit**</strong> Python error added:</p>
  
  <pre><code>Traceback (most recent call last):
    File "piu_billing.py", line 739, in &lt;module&gt;
      log_file.write(email_msg)
    File "piu_billing.py", line 102, in send_mail
      smtpserver.sendmail(office365_user,to,themsg)
    File "C:\Python27\lib\smtplib.py", line 719, in sendmail
      (code, resp) = self.mail(from_addr, esmtp_opts)
    File "C:\Python27\lib\smtplib.py", line 471, in mail
      self.putcmd("mail", "FROM:%s%s" % (quoteaddr(sender), optionlist))
    File "C:\Python27\lib\smtplib.py", line 334, in putcmd
       self.send(str)
    File "C:\Python27\lib\smtplib.py", line 324, in send
      raise SMTPServerDisconnected('Server not connected')
      smtplib.SMTPServerDisconnected: Server not connected
  </code></pre>