title: Python script should send me mail when there is any exception
body: <p>I want my Python script to send me mail me when there is any exception. I have tried some code related to SMTP that I found, but unfortunately it's not executing and showing an error.  Please help me to find out the main problem.</p>
  
  <p>The SMTP code:</p>
  
  <pre><code>import smtplib
  import string
  
  SERVER = 'localhost'
  SUBJECT = "Test email from Python"
  TO = "abc.def@defghij.com"
  FROM = "python@mydomain.com"
  text = "Sample of mail"
  BODY = string.join(("From: %s" % FROM,"To: %s" % TO,"Subject: %s" %SUBJECT ,"",text), "\r\n")
  
  server = smtplib.SMTP(SERVER) #Here in this line it showing error 
  
  server.sendmail(FROM,TO,BODY)
  
  server.quit()
  </code></pre>
  
  <blockquote>
    <p>** error message <em>*</em> server = smtplib.SMTP(SERVER)</p>
    
    <p>socket.error: (10047, 'Address family not supported by protocol family: See <a href="http://wiki.python.org/jython/NewSocketModule#IPV6addresssupport" rel="nofollow">http://wiki.python.org/jython/NewSocketModule#IPV6addresssupport</a>')</p>
  </blockquote>