Example #1
0
        public static void SendDeviceAlertMail(string deviceID, string levelCode, Dictionary <string, string> addresses)
        {
            DataSet ds = SqlHelper.GetDevicesAlert(deviceID, levelCode);                  // 获取DOWN数量的记录用来发送报警

            DataSet mi        = SqlHelper.GetDeviceAlertInformation(deviceID, levelCode); // 获取设备报警级别码的信息
            string  alertCode = mi.Tables[0].Rows[0]["alertCode"].ToString();             // 报警码
            string  message   = mi.Tables[0].Rows[0]["alertMessage"].ToString();          // 待发送的报警信息

            string        emailAddress = addresses["Level 0"];                            // 测试的时候发Level 0,正式的时候改为Level 1
            List <string> cc           = new List <string>();

            List <StoreAlertEmail> list = new List <StoreAlertEmail>();
            int rows = ds.Tables[0].Rows.Count;

            for (int i = 0; i < rows; i++)
            {
                StoreAlertEmail alert = new StoreAlertEmail();
                alert.StoreNo      = ds.Tables[0].Rows[i]["storeNo"].ToString();
                alert.StoreRegion  = ds.Tables[0].Rows[i]["storeRegion"].ToString();
                alert.StoreType    = ds.Tables[0].Rows[i]["storeType"].ToString();
                alert.DeviceID     = ds.Tables[0].Rows[i]["deviceID"].ToString();
                alert.DeviceName   = ds.Tables[0].Rows[i]["deviceName"].ToString();
                alert.DownCount    = ds.Tables[0].Rows[i]["downCount"].ToString();
                alert.Alert2       = ds.Tables[0].Rows[i]["alert2"].ToString();
                alert.Alert30      = ds.Tables[0].Rows[i]["alert30"].ToString();
                alert.EmailAddress = ds.Tables[0].Rows[i]["emailAddress"].ToString();

                string    subject   = alert.StoreNo + "门店 " + alert.DeviceName + "报警 状态:" + alertCode;
                EmailFrom emailFrom = new EmailFrom("[email protected] ", "1q2w3e4r", "59.60.9.101", 25);
                if (levelCode == "Alert30" || (levelCode == "Alert0" && alert.Alert30 == "1"))
                {
                    if (!cc.Contains(addresses["Level 4"]))
                    {
                        cc.Add(addresses["Level 4"]);                                     // 测试的时候发Level 4,正式的时候发Level 2
                    }
                }
                EmailHelper email = new EmailHelper(emailFrom, emailAddress, cc);

                if ((levelCode == "Alert2" && alert.Alert2 == "False") ||
                    (levelCode == "Alert30" && alert.Alert30 == "False") ||
                    (levelCode == "Alert0" && (alert.Alert2 == "True" || alert.Alert30 == "True")))
                {
                    if (email.SendMail(subject, message) == true)
                    {
                        alert.IsSend = true;
                        Console.WriteLine("{0} 发送成功!", alert.StoreNo);
                    }
                    else
                    {
                        alert.IsSend = false;
                        Console.WriteLine("{0} 发送失败!", alert.StoreNo);
                    }
                }
                else
                {
                    Console.WriteLine("{0} 已经发送过了!", alert.StoreNo);
                }
                list.Add(alert);
            }

            if (rows != 0)
            {
                SqlHelper.UpdateDevicesAlert(list, levelCode);           // 邮件发送状态更新到报警表
            }
        }
Example #2
0
        public static void SendLowinkEmailPerStore()
        {
            // 同步门店信息,当日发送邮件状态同步
            SqlHelper.SyncSendEmail();
            SqlHelper.UpdateIsSend();

            // 获取缺墨的门店
            List <string> storeNos = new List <string>();
            DataSet       lowink   = SqlHelper.GetLowInkPrinter();

            for (int i = 0; i < lowink.Tables[0].Rows.Count; i++)
            {
                storeNos.Add(lowink.Tables[0].Rows[i]["storeNo"].ToString());
            }

            // 获取缺墨门店的发送邮件状态
            DataSet ds    = SqlHelper.GetEmailIsSend(storeNos);
            int     count = ds.Tables[0].Rows.Count;

            bool[] status = new bool[count]; // 记录发送邮件的状态

            EmailFrom emailFrom = new EmailFrom("[email protected] ", "1q2w3e4r", "59.60.9.101", 25);

            List <string> cc = new List <string>();

            cc.Add("*****@*****.**");
            //cc.Add("*****@*****.**");


            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                string storeNo = ds.Tables[0].Rows[i]["storeNo"].ToString();
                string isSend  = ds.Tables[0].Rows[i]["isSend"].ToString();
                //string emailAddress = ds.Tables[0].Rows[i]["emailAddress"].ToString(); // 测试环境发给自己,正式环境发给门店
                string emailAddress  = "*****@*****.**";
                string region        = ds.Tables[0].Rows[i]["storeRegion"].ToString();
                string printerType   = ds.Tables[0].Rows[i]["printerType"].ToString();
                string tonerType     = ds.Tables[0].Rows[i]["tonerType"].ToString();
                string printerStatus = ds.Tables[0].Rows[i]["printerStatus"].ToString();
                string cnt           = ds.Tables[0].Rows[i]["cnt"].ToString();

                string subject  = storeNo + " 门店缺墨提醒";
                string mailBody = " <span style=\"color: rgb(255, 0, 0); font-size: 32px;\">系统邮件,不用回复!</span><br>" + storeNo + "门店墨盒不足10%,请注意更换! 如果需要采购新的硒鼓墨盒,请按以下格式填写信息后发送给([email protected]) <br><hr><br>";
                if (cnt == "1")
                {
                    mailBody = " <span style=\"color: rgb(255, 0, 0); font-size: 32px;\">系统邮件,不用回复!</span><br>" + storeNo + "门店墨盒不足<span style=\"color: rgb(255, 0, 0); font-size: 32px;\">1%</span>,请尽快更换! 如果需要采购新的硒鼓墨盒,请按以下格式填写信息后发送给([email protected]) <br><hr><br>";
                }
                mailBody += MailBodyMessage(storeNo, region, tonerType);

                string attach = null;
                string cd     = System.IO.Directory.GetCurrentDirectory();
                int    idx    = cd.IndexOf("IMonitorAssist");
                if (printerStatus == "10.0000 SUPPLY MEMORY ERROR")
                {
                    subject   = storeNo + " 门店硒鼓信息无法读取";
                    mailBody  = " <span style=\"color: rgb(255, 0, 0); font-size: 32px;\">系统邮件,不用回复!</span><br>" + storeNo + "门店墨盒信息无法读取 <br><hr><br>";
                    mailBody += "由于后台检测发现硒鼓出现 10.0000 SUPPLY MEMORY ERROR 错误信息,请按照附件的图片检查是否将 硒鼓黄色拉环 去除。";
                    attach    = cd.Substring(0, idx) + "IMonitorWeb\\contents\\XEFA.jpg";
                }

                EmailHelper email = new EmailHelper(emailFrom, emailAddress, cc);
                if (isSend == "False")
                {
                    if (email.SendMail(subject, mailBody, attach) == true)
                    {
                        status[i] = true;
                        Console.WriteLine("{0} 发送成功!", storeNo);
                    }
                    else
                    {
                        status[i] = false;
                        Console.WriteLine("{0} 发送失败!", storeNo);
                    }
                }
                else
                {
                    status[i] = true;
                    Console.WriteLine("{0} 已经发送过了!", storeNo);
                }
            }

            // 更新发送邮件状态到数据库
            List <SendEmail> sendEmail = new List <SendEmail>();

            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                SendEmail sendemail = new SendEmail();
                sendemail.StoreNo = ds.Tables[0].Rows[i][0].ToString();
                sendemail.IsSend  = status[i];
                sendEmail.Add(sendemail);
            }
            SqlHelper.UpdateIsSend(sendEmail);
        }
Example #3
0
 public EmailHelper(EmailFrom emailFrom, string to, List <string> cc)
 {
     From = emailFrom;
     To   = to;
     Cc   = cc;
 }