how to send email

 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;
        }
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值