title: python. Can I check if SMTP Server is disconnected (so I can connect again?)
body: <p>I am using <code>smtplib</code> and I am sending notification emails from my application. However I noticed that sometimes (especially when there is a lot of idle time between mail sending) I get a <code>SMTPServerDisconnected</code> error. </p>
  
  <p>I guess there are 2 solutions for this (know none of them, though)</p>
  
  <ol>
  <li>Increase idle time between sending mails</li>
  <li>reconnect when connection is down.</li>
  </ol>
  
  <p>I think 2nd solution seems more elegant. But how can I do that?</p>
  
  <p>edit: I am adding the code</p>
  
  <pre><code>from smtplib import SMTP
  smtp = SMTP()
  smtp.connect('smtp.server.com')
  smtp.login('username','password')
  
  def notifyUser():
      smtp.sendmail(from_email, to_email, msg.as_string())
  </code></pre>