cas | 33 ++++++++++++++++-----------------
1 file changed, 16 insertions(+), 17 deletions(-)
New commits:
commit d6545af9bcf05f71bb6d369fc10eec9e666da80b
Author: Adam Stokes <adam.stokes(a)gmail.com>
Date: Fri May 1 17:13:18 2009 -0400
- better failure handling of smtp
diff --git a/cas b/cas
index 412667e..3075d90 100755
--- a/cas
+++ b/cas
@@ -19,6 +19,7 @@ import optparse
import os
import ConfigParser
import smtplib
+import socket
from subprocess import Popen, PIPE
from datetime import datetime
@@ -332,25 +333,23 @@ class CasApplication(object):
if os.path.isfile(crashOutFile) and self.email:
self.casLog.info("Crash output processed, sending email to %s" %
(self.email,))
try:
- # Compose email msg of results
- msg = "Subject: CAS results for %s\r\n\n" % (self.identifier,)
- msg += "Location: %s\n" % (self.storagePath,)
- msg += "Server: %s\n" % (casProcessMachine,)
- msg += "Output data:\n"
- crashOutFH = open(crashOutFile,'r')
- msg += crashOutFH.read()
- crashOutFH.close()
+ mailServer = smtplib.SMTP(SMTPHOST)
try:
- # for some reason smtplib doesn't have proper exception handling
- # for name or service not known :(
- mailServer = smtplib.SMTP(SMTPHOST)
- except:
- self.casLog.debug("Unable to connect to mail server: %s, no
email " \
- "results sent." % (SMTPHOST,))
- mailServer.set_debuglevel(0)
- mailServer.sendmail(self.email,self.email,msg)
- mailServer.quit()
+ # Compose email msg of results
+ msg = "Subject: CAS results for %s\r\n\n" %
(self.identifier,)
+ msg += "Location: %s\n" % (self.storagePath,)
+ msg += "Server: %s\n" % (casProcessMachine,)
+ msg += "Output data:\n"
+ crashOutFH = open(crashOutFile,'r')
+ msg += crashOutFH.read()
+ crashOutFH.close()
+ #mailServer.set_debuglevel(0)
+ mailServer.sendmail(self.email,self.email,msg)
+ mailServer.quit(
except smtplib.SMTPException, e:
+ self.casLog.debug("Unable to connect to mail server: %s (%s), no
email " \
+ "results sent." % (SMTPHOST,str(e)))
+ except (os.error, socket.error), e:
self.casLog.debug(e)
self.casLog.info("Job on %s complete and located in %s." %
(self.filename,
self.storagePath))
Show replies by date