How to get notified via email on error in your application

I am presenting here a simple but useful way to get notified via email, when ever an error is happening in your asp.net application with out using try catch. I am creating a httpmodule in app_code for notifying errors. Here is the code for the module.

I am using my “EmailSender” utility for sending emails here. You can find that here. Using this method, first you should create a folder “MailTemplates” in your root folder and add a html template file for “ErrorNotification.htm” in that folder. You can get the referance for creating the html email template from here. Now add the following code in EmailSender class

You are almost done. Now we need to add the module to our application’s configuration file. Add the following configuration value to your web.config, inside system.web and system.webserver (for IIS7).

Hurrey, so it is done. Cheers and Happy coding.

Leave a Reply

Your email address will not be published. Required fields are marked *