Send email when error occurs

  • Thread starter Thread starter Andy G
  • Start date Start date
A

Andy G

Hi,

My plan is to use Try Catch statements to catch an error and then email it
to myself. I send the user to a custom error page and I would like to email
myself the asp.net error. I thought that I would just call a function to
send a mail in the Catch area of the Try Catch statement but it didn't work,
or maybe I just had it set up wrong. What is the best way to accoplish this
task, using a Try Catch or something else?

Thanks.
 
Configuring your SMTP server may be the problem. It can be complicated.
And, there are sometimes errors created by unexpected software interactions.
I chased around quite awhile before I uncovered the fact that McAfee's
antivirus program was blocking my SMTP port for example.

I would recommend that you examine closely the error being generated when
your code tries to do the email send.
 
I can send emails fine. The system already generates a number of automatic
emails. I just need to know where to catch the error that occurs and then
send that error to to myself. I apoligize, I know I wasn't clear before.
When I say 'Error', I am talking about ANY error that might occur in the
system when a user is using it. I want to be notified right away of what is
going on.

Hopefully that helps out.
 
Ah! In that case, you'll want to look at using the Application_Error
method in global.asax. This method fires when the HttpApplication
object raises an Error event.

There are some good articles around the topic of error logging using
Application_Error demonstrating how to get the last exception,
emailing a stack trace, etc.
 
Back
Top