MaxwellTurner
asked on
Coldfusion - notify administrator via email on error
Is it possible to be notified by an email whenenver a coldfusion error occurs ... specifically when there is an email error ... EG: an undeliverable email? ... but also if an error occurs on a page. I've searched through the administrator and google, but cannot find out how to do this ... if it is even possible.
Max
Max
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Yes the way you defined, You have to do like that, and everything will work according to you
You can also use the cflog atg inside the cfcatch statement to log all the rrors in a text fiel or you can use the DB to add the entries in the table and later check on that entries
You can also use the cflog atg inside the cfcatch statement to log all the rrors in a text fiel or you can use the DB to add the entries in the table and later check on that entries
How to get rid of EE's junk mail? I tried to get rid of my account but there's no delete button. So I changed my e-mail to Experts-Sexchange@mailinat or.com, only to find they don't send mail there. So I used a throw away Gmail account instead. So now I am relieved of their shit, I am going to send them some of mine!
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
@AltControl ... wtf??
@Hammo777 ... hmmm, that made me think ... I can import my mailsent log into a dbase a few times a day via windows scheduled task and then run a cf scheduled task to run a page periodically that will email me if new entries have been added.
@myselfrandhawa ... hmmm that also made think ... can I wrap my entire page in a cftry\catch to catch the other non-email errors (so I don't have to use Application.cfc)?
Max
@Hammo777 ... hmmm, that made me think ... I can import my mailsent log into a dbase a few times a day via windows scheduled task and then run a cf scheduled task to run a page periodically that will email me if new entries have been added.
@myselfrandhawa ... hmmm that also made think ... can I wrap my entire page in a cftry\catch to catch the other non-email errors (so I don't have to use Application.cfc)?
Max
no points..
can I wrap my entire page in a cftry\catch.... (so I don't have to use Application.cfc)?
You could, but why not use an Application.cfc? Then all your error handling code would be one place
rather than scattered across different pages.
to catch the other non-email errors
As @Hammo777 said you can't catch email errors with cftry/cfcatch anyway. Mail is spooled and sent by a different thread. So 99% of problems won't be reported to your cfm page, meaning you can't use cftry/cfcatch on them.
can I wrap my entire page in a cftry\catch.... (so I don't have to use Application.cfc)?
You could, but why not use an Application.cfc? Then all your error handling code would be one place
rather than scattered across different pages.
to catch the other non-email errors
As @Hammo777 said you can't catch email errors with cftry/cfcatch anyway. Mail is spooled and sent by a different thread. So 99% of problems won't be reported to your cfm page, meaning you can't use cftry/cfcatch on them.
ASKER
@aqx ... I see the sense in that. I just don't know much about Application, but I'll have to start learning ... I wasn't 100% sure if 'silent errors' meant that cftry/cfcatch would not catch the error - thanks for confirming that..
Thanks to everyone. I think I know what I have to do now.
Max
Thanks to everyone. I think I know what I have to do now.
Max
Setting one up for error handling only shouldn't be too hard. Here's a good intro
http://www.coldfusionjedi.com/index.cfm/2007/11/9/Applicationcfc-Methods-and-Example-Uses
http://www.coldfusionjedi.com/index.cfm/2007/11/9/Applicationcfc-Methods-and-Example-Uses
ASKER
Just realized that Application.cfc was introduced in v.7 ... I am working with v6.1 and Application.cfm ... does that matter for my purpose?
@aqx ... thanks for the resource, but I'm at the stage where I am not really sure what Application.xxx is and how/where to use it on my site., I wiill try find a beginner to application.cfm, but if you have any suggested reading, I'm all ears.
Max
@aqx ... thanks for the resource, but I'm at the stage where I am not really sure what Application.xxx is and how/where to use it on my site., I wiill try find a beginner to application.cfm, but if you have any suggested reading, I'm all ears.
Max
Then you can't use Application.cfc / onError then. You'd have to use an Application.cfm file instead.
The basics are you create a file named "Application.cfm" and stick in the root folder of your application. It'll apply to any cfm file in that folder AND any of it's subfolders. If an error occurs in any of those cfm pages, the error handler in your Application.cfm file will handle it.
Here's a simple example from Ray Camden's site. It's probably where myselfrandhawa got his example ;-)
http://www.coldfusionjedi.com/index.cfm/2007/12/5/The-Complete-Guide-to-Adding-Error-Handling-to-Your-ColdFusion-Application
The basics are you create a file named "Application.cfm" and stick in the root folder of your application. It'll apply to any cfm file in that folder AND any of it's subfolders. If an error occurs in any of those cfm pages, the error handler in your Application.cfm file will handle it.
Here's a simple example from Ray Camden's site. It's probably where myselfrandhawa got his example ;-)
http://www.coldfusionjedi.com/index.cfm/2007/12/5/The-Complete-Guide-to-Adding-Error-Handling-to-Your-ColdFusion-Application
FILE: Application.cfm
------------------------
<cfapplication name="rayrules">
<cferror type="exception" template="MyErrorHandler.cfm">
FILE: MyErrorHandler.cfm (place in same directory as "Application.cfm")
--------------------------
<!---
display a user friendly message first
--->
<h1>My Error Handler</h1>
We are so sorry. Something went wrong. We are working on it now.
<!---
next capture details about the error
--->
<cfsavecontent variable="errortext">
<cfoutput>
An error occurred: http://#cgi.server_name##cgi.script_name#?#cgi.query_string#<br />
Time: #dateFormat(now(), "short")# #timeFormat(now(), "short")#<br />
<cfdump var="#error#" label="Error">
<cfdump var="#form#" label="Form">
<cfdump var="#url#" label="URL">
</cfoutput>
</cfsavecontent>
<!---
finally email yourself the error details
--->
<cfmail to="youremail@yourcompany.com" from="errors@yourcompany.com" subject="Error: #error.message#" type="html">
#errortext#
</cfmail>
File: test.cfm (creates an error to test it out ...)
---------------------
<cfset a = 1>
<cfset b = a / 0>
if you have any suggested reading, I'm all ears.
Also check the definitive source of course. Not sure if the 6.1 docs are still on line, but here's v8
http://livedocs.adobe.com/coldfusion/8/Errors_01.html
Also check the definitive source of course. Not sure if the 6.1 docs are still on line, but here's v8
http://livedocs.adobe.com/coldfusion/8/Errors_01.html
ASKER
[cftry]
[cfmail] ...[/cfmail] - to user
[cfcatch]
[cfmail] ... [/cfmail] - to administrator
[/cfcatch]
[/cftry]
Max