From f7de4c9e9489bc0cda070833ea3022d0a2d637c5 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Wed, 31 Oct 2007 23:33:09 +0000 Subject: [PATCH] Now emailing tracebacks to support email address. --- config/Common.py | 2 +- controller/Expose.py | 2 +- controller/Root.py | 32 +++++++++++++++++++++++++++++++- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/config/Common.py b/config/Common.py index 575d68f..aaf46dc 100644 --- a/config/Common.py +++ b/config/Common.py @@ -22,7 +22,7 @@ settings = { "luminotes.https_url": "", "luminotes.http_proxy_ip": "127.0.0.1", "luminotes.https_proxy_ip": "127.0.0.2", - "luminotes.support_email": "support@luminotes.com", + "luminotes.support_email": "", "luminotes.rate_plans": [ { "name": "basic", diff --git a/controller/Expose.py b/controller/Expose.py index 214b2a0..ec1f0c3 100644 --- a/controller/Expose.py +++ b/controller/Expose.py @@ -55,9 +55,9 @@ def expose( view = None, rss = None ): if hasattr( error, "to_dict" ): result = error.to_dict() else: - # TODO: it'd be nice to send an email to myself with the traceback import traceback traceback.print_exc() + cherrypy.root.report_traceback() result = dict( error = u"An error occurred when processing your request. Please try again or contact support." ) redirect = result.get( u"redirect", None ) diff --git a/controller/Root.py b/controller/Root.py index bb67ed4..d4d7a3e 100644 --- a/controller/Root.py +++ b/controller/Root.py @@ -164,12 +164,42 @@ class Root( object ): cherrypy.response.body = [ unicode( Not_found_page( support_email ) ) ] return - # TODO: it'd be nice to send an email to myself with the traceback import traceback traceback.print_exc() + self.report_traceback() cherrypy.response.body = [ unicode( Error_page( support_email ) ) ] + def report_traceback( self ): + """ + If a support email address is configured, send it an email with the current traceback. + """ + support_email = self.__settings[ u"global" ].get( u"luminotes.support_email" ) + if not support_email: return False + + import smtplib + import traceback + from email import Message + + message = Message.Message() + message[ u"from" ] = support_email + message[ u"to" ] = support_email + message[ u"subject" ] = u"Luminotes traceback" + message.set_payload( + u"requested URL: %s\n" % cherrypy.request.browser_url + + u"user id: %s\n" % cherrypy.session.get( "user_id" ) + + u"username: %s\n\n" % cherrypy.session.get( "username" ) + + traceback.format_exc() + ) + + # send the message out through localhost's smtp server + server = smtplib.SMTP() + server.connect() + server.sendmail( message[ u"from" ], [ support_email ], message.as_string() ) + server.quit() + + return True + database = property( lambda self: self.__database ) notebooks = property( lambda self: self.__notebooks ) users = property( lambda self: self.__users )