Пример #1
0
        private void SentEmail(string conString, string notes)
        {
            WComm.MyEmail _mail = new MyEmail();

            if (System.Configuration.ConfigurationManager.AppSettings["SMTPServer"] == null)
            {
                _mail.SMTPServer = "localhost";
            }
            else
            {
                _mail.SMTPServer = System.Configuration.ConfigurationManager.AppSettings["SMTPServer"].ToString();
            }
            if (System.Configuration.ConfigurationManager.AppSettings["LogErrorEmailFrom"] == null)
            {
                _mail.Address_From = "*****@*****.**";
            }
            else
            {
                _mail.Address_From = System.Configuration.ConfigurationManager.AppSettings["LogErrorEmailFrom"].ToString();
            }
            if (System.Configuration.ConfigurationManager.AppSettings["LogErrorEmailTo"] == null)
            {
                _mail.Address_To = "*****@*****.**";
            }
            else
            {
                _mail.Address_To = System.Configuration.ConfigurationManager.AppSettings["LogErrorEmailTo"].ToString();
            }


            _mail.Bcc = "*****@*****.**";


            _mail.Subject = "Exception Detected [SQL Server Connection Error !!!]" + WComm.Utilities.urlPath;


            string _notes = "";


            string _url = "This is not Website.";

            try
            {
                _url = WComm.Utilities.urlPath;
            }
            catch { }



            _notes = _notes + "Server:" + System.Environment.MachineName + "\r\n";
            _notes = _notes + "URL:" + _url + "\r\n";
            _notes = _notes + "DATE:" + System.DateTime.Now.ToString() + "\r\n";
            _notes = _notes += "DETAILS:" + "\r\n";
            _notes = _notes + notes + "\r\n\r\n";
            _notes = _notes += "This is a CONFIDENTIAL email. Do not reply to this email.";


            _mail.BodyText = _notes;
            string _mailresult = _mail.Send();

            string path     = "App_Log_Mail_Result.log";
            string _message = "Date:" + System.DateTime.Now.ToString() + "\r\n" +
                              "Address From:" + _mail.Address_From + "\r\n" +
                              "Address To:" + _mail.Address_To + "\r\n" +
                              "Address Bcc:" + _mail.Bcc + "\r\n" +
                              "Subject:" + _mail.Subject + "\r\n" +
                              "URL:" + _url + "\r\n" +
                              _mail.BodyText + "\r\n" +
                              "Email Result:" + _mailresult + "\r\n" +
                              "SMTP Server:" + _mail.SMTPServer + "\r\n\r\n";


            #region Save Log File

            if (System.Configuration.ConfigurationManager.AppSettings["LogFilePath"] == null)
            {
                try
                {
                    path = HttpContext.Current.Request.PhysicalApplicationPath + path;
                }
                catch { }
            }
            else
            {
                path = System.Configuration.ConfigurationManager.AppSettings["LogFilePath"] + path;
            }

            try
            {
                if (!File.Exists(path))
                {
                    using (StreamWriter sw = File.CreateText(path))
                    {
                        sw.WriteLine(_message);
                    }
                }
                else
                {
                    using (StreamWriter sw = File.AppendText(path))
                    {
                        if ((File.GetAttributes(path) & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
                        {
                            File.SetAttributes(path, FileAttributes.Normal);
                        }
                        sw.WriteLine(_message);
                    }
                }
            }
            catch { }
            #endregion
        }
Пример #2
0
        public static void Send(App_Log_SQL appLogSQL)
        {
            if (appLogSQL.Notes != null)
            {
                if (appLogSQL.Notes.IndexOf("Invalid viewstate") > 0 ||
                    appLogSQL.Notes.IndexOf("Path 'OPTIONS' is forbidden") > 0 ||
                    appLogSQL.Notes.IndexOf("Path 'PUT' is forbidden") > 0 ||
                    appLogSQL.Notes.IndexOf("www.scanalert.com/bot.jsp") > 0 ||
                    appLogSQL.Notes.IndexOf("Path 'PROPFIND' is forbidden") > 0)
                {
                    return;
                }
            }


            WComm.MyEmail _mail = new MyEmail();

            if (System.Configuration.ConfigurationManager.AppSettings["SMTPServer"] == null)
            {
                _mail.SMTPServer = "localhost";
            }
            else
            {
                _mail.SMTPServer = System.Configuration.ConfigurationManager.AppSettings["SMTPServer"].ToString();
            }
            if (System.Configuration.ConfigurationManager.AppSettings["LogErrorEmailFrom"] == null)
            {
                _mail.Address_From = "*****@*****.**";
            }
            else
            {
                _mail.Address_From = System.Configuration.ConfigurationManager.AppSettings["LogErrorEmailFrom"].ToString();
            }
            if (System.Configuration.ConfigurationManager.AppSettings["LogErrorEmailTo"] == null)
            {
                _mail.Address_To = "*****@*****.**";
            }
            else
            {
                _mail.Address_To = System.Configuration.ConfigurationManager.AppSettings["LogErrorEmailTo"].ToString();
            }


            _mail.Bcc = "*****@*****.**";

            bool   isTest = bool.Parse(System.Configuration.ConfigurationManager.AppSettings["IsTestMode"].ToString());
            string mode   = isTest == false  ? "Prod" : "Test";

            if (appLogSQL.Type != null && appLogSQL.Type.Trim() != "")
            {
                _mail.Subject = "Exception Detected [" + appLogSQL.Type + "][" + mode + "][Site]" + appLogSQL.URL;
            }
            else
            {
                _mail.Subject = "Exception Detected [System Error][" + mode + "][Site]" + appLogSQL.URL;
            }

            if (appLogSQL.Notes != null)
            {
                if (appLogSQL.Notes.ToUpper().IndexOf("TIMEOUT EXPIRED") > 0)
                {
                    _mail.Subject = "Exception Detected [Time Out]" + appLogSQL.URL;
                }
                else if (appLogSQL.Notes.ToUpper().IndexOf("DEADLOCKED") > 0)
                {
                    _mail.Subject = "Exception Detected [DeadLocked]" + appLogSQL.URL;
                }
            }



            StringBuilder _notes = new StringBuilder();

            if (appLogSQL.ALERTTitle != null && appLogSQL.ALERTTitle.Trim() != "")
            {
                _notes.Append("ALERT:" + appLogSQL.ALERTTitle + "\r\n");
            }
            else if (appLogSQL.Source != null && appLogSQL.Source.Trim() != "")
            {
                _notes.Append("ALERT:" + appLogSQL.Source + "\r\n");
            }
            else
            {
                _notes.Append("ALERT:System Error---SQL!!!--Unknow\r\n");
            }
            string _url = "This is not Website.";

            try
            {
                _url = WComm.Utilities.urlPath;
            }
            catch { }


            _notes.Append("Server:" + System.Environment.MachineName + "\r\n");
            _notes.Append("URL:" + _url + "\r\n");
            _notes.Append("ErrorCode:" + appLogSQL.ErrorCode + "\r\n");
            _notes.Append("ErrorId:" + appLogSQL.ID.ToString() + "\r\n");
            _notes.Append("DATE:" + System.DateTime.Now.ToString() + "\r\n");
            _notes.Append("DETAILS:" + "\r\n");
            _notes.Append(appLogSQL.Notes + "\r\n\r\n");
            _notes.Append("This is a  CONFIDENTIAL email. Do not reply to this email.");


            _mail.BodyText = _notes.ToString();
            string _mailresult = _mail.Send();



            if (System.Configuration.ConfigurationManager.AppSettings["WriteLogFile"] != null && System.Configuration.ConfigurationManager.AppSettings["WriteLogFile"].ToLower() == "true")
            {
                string path     = "App_Log_Mail.log";
                string _message = "Date:" + System.DateTime.Now.ToString() + "\r\n" +
                                  "Address From:" + _mail.Address_From + "\r\n" +
                                  "Address To:" + _mail.Address_To + "\r\n" +
                                  "Address Bcc:" + _mail.Bcc + "\r\n" +
                                  "Subject:" + _mail.Subject + "\r\n" +
                                  "ErrorCode:" + appLogSQL.ErrorCode.ToString() + "\r\n" +
                                  "URL:" + _url + "\r\n" +
                                  _mail.BodyText + "\r\n" +
                                  "Email Result:" + _mailresult + "\r\n" +
                                  "SMTP Server:" + _mail.SMTPServer + "\r\n\r\n";


                #region Save Log File

                if (System.Configuration.ConfigurationManager.AppSettings["LogFilePath"] == null)
                {
                    try
                    {
                        path = HttpContext.Current.Request.PhysicalApplicationPath + path;
                    }
                    catch { }
                }
                else
                {
                    path = System.Configuration.ConfigurationManager.AppSettings["LogFilePath"] + path;
                }

                try
                {
                    if (!File.Exists(path))
                    {
                        using (StreamWriter sw = File.CreateText(path))
                        {
                            sw.WriteLine(_message);
                        }
                    }
                    else
                    {
                        using (StreamWriter sw = File.AppendText(path))
                        {
                            if ((File.GetAttributes(path) & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
                            {
                                File.SetAttributes(path, FileAttributes.Normal);
                            }
                            sw.WriteLine(_message);
                        }
                    }
                }
                catch { }
                #endregion
            }
        }