Example #1
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][0].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("*****@*****.**");
            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 region       = ds.Tables[0].Rows[i]["storeRegion"].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>";
                mailBody += MailBodyMessage(storeNo, region);

                EmailHelper email = new EmailHelper(emailFrom, emailAddress, cc);
                if (isSend == "False")
                {
                    if (email.SendMail(subject, mailBody) == 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 #2
0
 public EmailHelper(EmailFrom emailFrom, string to, List <string> cc)
 {
     From = emailFrom;
     To   = to;
     Cc   = cc;
 }
Example #3
0
        public static void SendLowinkEmail()
        {
            // 同步门店信息,当日发送邮件状态同步
            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][0].ToString());
            }

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

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

            // EmailFrom emailFrom = new EmailFrom("*****@*****.**", "iwooo2014", "smtp.163.com", 25);
            EmailFrom emailFrom = new EmailFrom("*****@*****.**", "finkle1986819", "59.60.9.101", 25);

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

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

            string subject  = DateTime.Now.ToString("yyyy-MM-dd") + " 门店打印机缺墨提醒";
            string mailBody = "以下门店墨盒不足10%,请尽快更换!<br>";
            int    flag     = 0;

            for (int i = 0; i < count; i++)
            {
                string storeNo = ds.Tables[0].Rows[i][0].ToString();
                string isSend  = ds.Tables[0].Rows[i][1].ToString();
                if (isSend == "False")
                {
                    mailBody += " " + storeNo + ",";
                }
                else
                {
                    flag++;  // 记录已发送过邮件的数量,如果和缺墨的门店的数量一样说明都发送过了
                }
                status[i] = true;
            }
            mailBody = mailBody.TrimEnd(',') + "<br>共 " + (count - flag).ToString() + " 家门店";
            EmailHelper email = new EmailHelper(emailFrom, "*****@*****.**", cc);

            if (flag == count)
            {
                Console.WriteLine("所有门店已经通知了");
            }
            else
            {
                if (email.SendMail(subject, mailBody) == true)
                {
                    Console.WriteLine("邮件发送成功!");
                }
                else
                {
                    // 发送失败,需要回滚isSend的状态
                    for (int i = 0; i < count; i++)
                    {
                        string isSend = ds.Tables[0].Rows[i][1].ToString();
                        if (isSend == "False")
                        {
                            status[i] = false;
                        }
                    }
                    Console.WriteLine("邮件发送失败!");
                }
            }
            // 更新发送邮件状态到数据库
            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 #4
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][0].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("*****@*****.**");
            //cc.Add("*****@*****.**");

            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                string storeNo = ds.Tables[0].Rows[i][0].ToString();
                string isSend = ds.Tables[0].Rows[i][1].ToString();
                string emailAddress = ds.Tables[0].Rows[i][2].ToString();

                string subject = storeNo + " 门店缺墨";
                string mailBody = storeNo + " 门店墨盒不足10%,请注意更换!";
                EmailHelper email = new EmailHelper(emailFrom, "*****@*****.**", cc);
                if (isSend == "False")
                {
                    if (email.SendMail(subject, mailBody) == 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 #5
0
        public static void SendLowinkEmail()
        {
            // 同步门店信息,当日发送邮件状态同步
            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][0].ToString());
            }

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

            // EmailFrom emailFrom = new EmailFrom("*****@*****.**", "iwooo2014", "smtp.163.com", 25);
            EmailFrom emailFrom = new EmailFrom("*****@*****.**", "finkle1986819", "59.60.9.101", 25);

            List<string> cc = new List<string>();
            DataSet emailAddress = SqlHelper.GetEmailAddress(storeNos);
            //cc.Add("*****@*****.**");
            cc.Add("*****@*****.**");

            string subject = DateTime.Now.ToString("yyyy-MM-dd") + " 门店打印机缺墨提醒";
            string mailBody = "以下门店墨盒不足10%,请尽快更换!<br>";
            int flag = 0;
            for (int i = 0; i < count; i++)
            {
                string storeNo = ds.Tables[0].Rows[i][0].ToString();
                string isSend = ds.Tables[0].Rows[i][1].ToString();
                if (isSend == "False")
                {
                    mailBody += " " + storeNo + ",";
                }
                else
                {
                    flag++;  // 记录已发送过邮件的数量,如果和缺墨的门店的数量一样说明都发送过了
                }
                status[i] = true;
            }
            mailBody = mailBody.TrimEnd(',') + "<br>共 " + (count - flag).ToString() + " 家门店";
            EmailHelper email = new EmailHelper(emailFrom, "*****@*****.**", cc);

            if (flag == count)
            {
                Console.WriteLine("所有门店已经通知了");
            }
            else
            {
                if (email.SendMail(subject, mailBody) == true)
                {
                    Console.WriteLine("邮件发送成功!");
                }
                else
                {
                    // 发送失败,需要回滚isSend的状态
                    for (int i = 0; i < count; i++)
                    {
                        string isSend = ds.Tables[0].Rows[i][1].ToString();
                        if (isSend == "False")
                        {
                            status[i] = false;
                        }
                    }
                    Console.WriteLine("邮件发送失败!");
                }
            }
            // 更新发送邮件状态到数据库
            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 #6
0
 public EmailHelper(EmailFrom emailFrom, string to, List<string> cc)
 {
     From = emailFrom;
     To = to;
     Cc = cc;
 }
Example #7
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][0].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("*****@*****.**");
            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 region = ds.Tables[0].Rows[i]["storeRegion"].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>";
                mailBody += MailBodyMessage(storeNo, region);

                EmailHelper email = new EmailHelper(emailFrom, emailAddress, cc);
                if (isSend == "False")
                {
                    if (email.SendMail(subject, mailBody) == 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);
        }