您的位置:首页 > 大数据 > 人工智能

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;

        }

    }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息