public static void MailErrorMessageToDevTeam(Exception ex, String loginUserId,
String[] additionalInfo)
{
try
{
//
Code to send email to the development team
//
String bodyContent = null;
bodyContent = "<html>/n<head><title>Errors on Portal Software</title></head>/n<body>";
bodyContent += "<table><tr><td bgcolor=efefef><font face='Tahoma'><h3>Errors on Portal Software</td></h3></font></tr>/n";
bodyContent += " <tr><td bgcolor=efefff><font face='Tahoma' size=4>/n";
bodyContent += "<pre>";
if (loginUserId!=null)
{
bodyContent += "LOGIN USER: " + loginUserId + "/n/n";
}
if (ex.Message != null)
{
bodyContent += "Exception Message:/n";
bodyContent += "/t" + ex.Message.ToString() + "/n/n";
}
if (ex.StackTrace != null)
{
bodyContent += "Exception Trace:/n";
bodyContent += ex.StackTrace.ToString() + "/n";
}
if (additionalInfo != null)
{
bodyContent += "Additional Information:/n";
for (int i = 0; i < additionalInfo.Length; i++)
{
bodyContent += additionalInfo[i] + "/n";
}
}
bodyContent += "</pre>";
bodyContent += "Sincerely,<p>" + "The " + System.Configuration.ConfigurationManager.AppSettings[Globals.APPCONFIG_COMPANY_NAME]
+ System.Configuration.ConfigurationManager.AppSettings[Globals.APPCONFIG_APPLICATION_NAME];
bodyContent += "</font></td></tr></table>";
bodyContent += "</body></html>";
System.Net.Mail.MailMessage mailMsg = new System.Net.Mail.MailMessage();
//System.Web.Mail.MailMessage mailMsg = new System.Web.Mail.MailMessage();
mailMsg.From = new MailAddress( System.Configuration.ConfigurationManager.AppSettings[Globals.APPCONFIG_ERROR_EMAIL_FROM_ADDRESS]);
mailMsg.To.Add(new MailAddress (System.Configuration.ConfigurationManager.AppSettings[Globals.APPCONFIG_ERROR_EMAIL_TO_ADDRESS]));
mailMsg.Subject = System.Configuration.ConfigurationManager.AppSettings[Globals.APPCONFIG_APPLICATION_NAME] + " ERROR";
mailMsg.Body = bodyContent;
mailMsg.BodyEncoding = System.Text.Encoding.ASCII;
//mailMsg.BodyFormat = MailFormat.Html;
mailMsg.IsBodyHtml = true;
//mailMsg.Priority = System.Web.Mail.MailPriority.High;
mailMsg.Priority = System.Net.Mail.MailPriority.High;
// sends it to the localhost's SMTP mail server, by DEFAULT
// SmtpMail.Send(mailMsg);
string smtpAddress = ConfigurationManager.AppSettings["SmtpServer"].ToString();
SmtpClient smtp = new SmtpClient(smtpAddress);
smtp.Send(mailMsg); //in case test send junk email
}
catch (Exception e)
{
object o = e;
}
}
how to send email
最新推荐文章于 2014-11-28 03:25:39 发布