T
tafs7
My code below is supposed to email me when an error occurs on the
application, but it's not emailing anything. Am I missing something?
I know the smtp servers I've tried work. I even added a App_Start
handler to see if I could get emailed at all even from the first
request of the app, but to no avail. Could someone please help me
out? Thanks a lot!
--Thiago
Web developer
AgniTEK
GLOBAL.ASAX:
------------
<%@ Application Description="FOO" %>
<%@ Import Namespace = "System.Diagnostics" %>
<%@ Import Namespace = "System.Data" %>
<%@ Import Namespace = "System.Data.SqlClient" %>
<%@ Import Namespace = "System.Web.Security" %>
<%@ Import Namespace = "System.Web.Mail" %>
<%@ Import Namespace = "System.Text" %>
<script language="c#" runat="server">
void Application_Error (Object sender, EventArgs e)
{
String msg = "\n\nURL:\n " + Request.ApplicationPath
+ "\n\nMESSAGE:\n " + Server.GetLastError().Message
+ "\n\nSTACK TRACE:\n" + Server.GetLastError().StackTrace;
// Create Event Log if it does not exist
String LogName = "Application";
if (!EventLog.SourceExists(LogName)) {
EventLog.CreateEventSource(LogName, LogName);
}
// Insert into Event Log
EventLog Log = new EventLog();
Log.Source = LogName;
Log.WriteEntry(msg, EventLogEntryType.Error);
//create an email message for the admin
MailMessage mailMsg = new MailMessage();
mailMsg.To = "(e-mail address removed)";
mailMsg.From = "(e-mail address removed)";
mailMsg.Subject = "Application Error";
mailMsg.Body = msg;
//send the email
SmtpMail.SmtpServer = "[server name here]";
SmtpMail.Send(mailMsg);
}
void Application_Start (Object sender, EventArgs e)
{
//create an email message for the admin
MailMessage mailMsg = new MailMessage();
mailMsg.To = "(e-mail address removed)";
mailMsg.From = "(e-mail address removed)";
mailMsg.Subject = "Application started";
mailMsg.Body = "App started";
//send the email
SmtpMail.SmtpServer = "[server name here]";
SmtpMail.Send(mailMsg);
}
</script>
application, but it's not emailing anything. Am I missing something?
I know the smtp servers I've tried work. I even added a App_Start
handler to see if I could get emailed at all even from the first
request of the app, but to no avail. Could someone please help me
out? Thanks a lot!
--Thiago
Web developer
AgniTEK
GLOBAL.ASAX:
------------
<%@ Application Description="FOO" %>
<%@ Import Namespace = "System.Diagnostics" %>
<%@ Import Namespace = "System.Data" %>
<%@ Import Namespace = "System.Data.SqlClient" %>
<%@ Import Namespace = "System.Web.Security" %>
<%@ Import Namespace = "System.Web.Mail" %>
<%@ Import Namespace = "System.Text" %>
<script language="c#" runat="server">
void Application_Error (Object sender, EventArgs e)
{
String msg = "\n\nURL:\n " + Request.ApplicationPath
+ "\n\nMESSAGE:\n " + Server.GetLastError().Message
+ "\n\nSTACK TRACE:\n" + Server.GetLastError().StackTrace;
// Create Event Log if it does not exist
String LogName = "Application";
if (!EventLog.SourceExists(LogName)) {
EventLog.CreateEventSource(LogName, LogName);
}
// Insert into Event Log
EventLog Log = new EventLog();
Log.Source = LogName;
Log.WriteEntry(msg, EventLogEntryType.Error);
//create an email message for the admin
MailMessage mailMsg = new MailMessage();
mailMsg.To = "(e-mail address removed)";
mailMsg.From = "(e-mail address removed)";
mailMsg.Subject = "Application Error";
mailMsg.Body = msg;
//send the email
SmtpMail.SmtpServer = "[server name here]";
SmtpMail.Send(mailMsg);
}
void Application_Start (Object sender, EventArgs e)
{
//create an email message for the admin
MailMessage mailMsg = new MailMessage();
mailMsg.To = "(e-mail address removed)";
mailMsg.From = "(e-mail address removed)";
mailMsg.Subject = "Application started";
mailMsg.Body = "App started";
//send the email
SmtpMail.SmtpServer = "[server name here]";
SmtpMail.Send(mailMsg);
}
</script>