1: protected void Application_Error(object sender, EventArgs e)
2: {
3: string ErrorDescription = "Server : " + System.Environment.MachineName + "\n\n";
4: ErrorDescription += "Request.Path : " + Request.Path + "\n\n";
5: System.Exception error = Server.GetLastError();
6: EmailError(
7: youremailaddress@website.com, //to
8: youremailaddress@website.com, //from
9: "Application Error : "+Server.MachineName, //subject
10: ErrorDescription + error.ToString(), //body,
11: "youremailserver", //Mail Server
12: 25 //25 is the default port for email, change if necessary
13: );
14: }
15:
16: private void EmailError(string to,string from,string subject,
17: string body,string mailServerHost,int mailServerPort)
18: {
19: try
20: {
21: System.Net.Mail.MailMessage MailMessage = new System.Net.Mail.MailMessage();
22: MailMessage.Priority = System.Net.Mail.MailPriority.High;
23: MailMessage.To.Add(to);
24: MailMessage.From = new System.Net.Mail.MailAddress(from);
25: MailMessage.Subject = subject;
26: MailMessage.Body = body;
27: System.Net.Mail.SmtpClient smtpClient = new System.Net.Mail.SmtpClient(mailServerHost, mailServerPort);
28: smtpClient.Send(MailMessage);
29: }
30: catch
31: {
32: }
33: }