using System.Net.Mail;
public void SendPageErrorMailToAdmin(string ErrorPageName, string ExceptionMessage)
{
string _to = System.Configuration.ConfigurationManager.AppSettings ["SiteMasterEmail"];
string _from = System.Configuration.ConfigurationManager.AppSettings ["AdminEmail"];
//string _to = System.Configuration.ConfigurationManager.AppSettings ["ContactEmail"];
MailAddress from = new MailAddress( _from, "My Website Admin");
MailAddress to = new MailAddress( _to, "My SiteMaster");
MailMessage msg = new MailMessage( from, to);
msg.Body = "Dear SiteMaster, An Exception Has Been Found !" + Environment.NewLine;
msg.Body += "=============================================" + Environment.NewLine;
msg.Body += Environment.NewLine;
//=====Testing Lines, Not To Be Included in the Main Site.
//msg.Body += "//=====Testing Line, Not To Be Included in the Main Site." + Environment.NewLine;
//msg.Body += "(From " + _from + " To " + _to + ")" + Environment.NewLine;
msg.Body += Environment.NewLine;
msg.Body += "ExceptionPage : " + ErrorPageName + "." + Environment.NewLine;
msg.Body += Environment.NewLine;
msg.Body += Environment.NewLine;
msg.Body += "Exception : " + Environment.NewLine;
msg.Body += ExceptionMessage + ".";
msg.Body += Environment.NewLine;
msg.Body += Environment.NewLine;
msg.Body += Environment.NewLine;
msg.Body += "Needs To Be Corrected Immediately." + Environment.NewLine;
msg.Body += "Thanks" + Environment.NewLine;
msg.BodyEncoding = System.Text.Encoding.UTF8;
msg.Subject = "An Exception on " + ErrorPageName + " page.";
msg.Priority = MailPriority.High;
SmtpClient smtpObj = new SmtpClient("127.0.0.1");
smtpObj.Send(msg);
}
-
ShriKrishna Bhardwaj , With ASP.Net, SQL Server, Javascript