how to send email
2010-10-20 15:30
295 查看
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;
}
}
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 via Django?
- How to Send an Email Using UTL_SMTP with Authenticated Mail Server. (文档 ID 885522.1)
- How to test if the server is configured well to send email to external accoun
- How to send email via vbs using cdo
- How to send Email through external SMTP server on Ubuntu 14.04
- How do I authenticate to send an email
- how to send email by jmail?
- How to send Email asynchronously
- Salesforce: How to Send Email with Default Template?
- iOS Programming 101: How To Send Email in Your iPhone App
- How to Send an Email Using UTL_SMTP with Authenticated Mail Server
- How to make NAnt send an email using a real account
- How to Send an Email Using UTL_SMTP with Authenticated Mail Server
- How to Send an Email Using UTL_SMTP with Authenticated Mail Server
- prjSendMailInUniversity - How to send email using VB &amp; Winsock - 邮件发送接收程序 - VB6 + Winsock
- Custom checkout cart – How to send email after successful checkout
- 创造应用英语环境学英语-how to send email
- Custom checkout cart – How to send email after successful checkout
- How to send email using sqlserver
- How to Use git send-email