public override void Run()
 {
     LogHelper.Info("Panther.Email.Services.SendEmail.SmartSendEmail->Run()");
     //ping
     if (!PingHelper.TryConnect("www.baidu.com") && !PingHelper.TryConnect("www.google.cn"))
     {
         LogHelper.Error("无法连接連接網絡。");
         return;
     }
     while (IsStart)
     {
         List <EmailInfo> emailList = GetSendEmailList();
         if (emailList == null || emailList.Count <= 0)
         {
             LogHelper.Info("本次掃描完畢,沒有符合條件的發送郵件");
         }
         else
         {
             foreach (var emailInfo in emailList)
             {
                 //获取需要发送的邮件
                 //EmailInfo emailInfo = GetNextEmail();
                 if (emailInfo == null || emailInfo.EmailID == null)
                 {
                     LogHelper.Info("本次掃描完畢,沒有符合條件的發送郵件2");
                     continue;
                 }
                 //检测eml是否存在
                 if (string.IsNullOrEmpty(emailInfo.EmailFilePath))
                 {
                     //修改状态
                     emailInfo.EmailState = -1;
                     EmailInfoBLL emailinfobll = new EmailInfoBLL();
                     emailinfobll.Update(emailInfo);
                     LogHelper.Info("邮件正文為空,无法发送");
                     continue;
                 }
                 SendEmail(emailInfo);
                 //var t = new Thread(s =>
                 //    {
                 //        var info = s as EmailInfo;
                 //        SendEmail(info);
                 //    });
                 //t.Start(emailInfo);
             }
         }
         SleepInterval(Interval);
     }
 }
        void SendEmail(EmailInfo emailInfo)
        {
            //if (SendingEmailInfo.Where(e => e.EmailID == emailInfo.EmailID).Count() > 0)
            //{
            //    //如果已经在发送队列里面了
            //    return;
            //}
            //获取发送邮件的邮箱集合
            List <EmailAccount> emailAccountList = GetEmailSendAccount(emailInfo);

            if (emailAccountList == null || emailAccountList.Count <= 0)
            {
                return;
            }
            //判断是否有邮箱是可用状态
            if (emailAccountList.Where(a => a.EmailAccountLastTime <= DateTime.Now && a.EmailAccountRemainEmailCount > 0).Count() <= 0)
            {
                return;
            }
            //如果待发送bcc一个人都没,直接返回
            var tempBccAccount = GetEmailSendBccAccounts(emailInfo, 1);

            if (tempBccAccount == null || tempBccAccount.Count <= 0)
            {
                return;
            }
            //SendingEmailInfo.Add(emailInfo);
            var complete = false;

            foreach (EmailAccount emailAccount in emailAccountList)
            {
                LogHelper.Info(string.Format("發送帳號為:{0},發送郵件:{1}", emailAccount.EmailAccountAddress, emailInfo.EmailTitle));
            }
            while (!complete && IsStart)
            {
                foreach (EmailAccount ea in emailAccountList)
                {
                    //不额外增加获取指定邮箱 直接获取全部
                    var eaList = GetEmailSendAccount(emailInfo);
                    if (eaList == null || eaList.Count() <= 0 || eaList.Where(a => a.EmailAccountID == ea.EmailAccountID).Count() <= 0)
                    {
                        continue;
                    }
                    //每次发送前再获取一次数据防止在其他电脑使用了
                    var emailAccount = eaList.Where(a => a.EmailAccountID == ea.EmailAccountID).FirstOrDefault();
                    //当前邮箱的下次发送时间小等于当前时间,并且剩余发送数量大于0
                    if (emailAccount.EmailAccountLastTime <= DateTime.Now && emailAccount.EmailAccountRemainEmailCount > 0)
                    {
                        //如果上一次发送时间离当前时间大于1个间隔时间,就将可发生数量改为最大可发送数量
                        if (emailAccount.EmailAccountCreateTime.Value.AddMinutes(emailAccount.EmailAccountSpace) < DateTime.Now)
                        {
                            emailAccount.EmailAccountRemainEmailCount = emailAccount.EmailAccountMaxEmailCount;
                        }
                        var emailBccAccount = GetEmailSendBccAccounts(emailInfo, emailAccount.EmailAccountRemainEmailCount);
                        //判断邮件发送是否完成,获取到的邮件数量为0或者为空,就相当于发送完毕
                        if (emailBccAccount == null || emailBccAccount.Count <= 0)
                        {
                            //修改为已完成
                            emailInfo.EmailState = 1;
                            EmailInfoBLL emailinfoBLL = new EmailInfoBLL();
                            emailinfoBLL.Update(emailInfo);
                            complete = true;
                            break;
                        }
                        //发送状态0未发送,1已发送,-1发送失败,3正在发送
                        try
                        {
                            SendEmailBCCAccount(emailInfo, emailAccount, emailBccAccount);
                        }
                        catch (Exception ex)
                        {
                            LogHelper.Error("發送郵件", "線程操作", ex.Message, ex);
                        }
                        SleepInterval(Interval * 2);
                    }
                }
                SleepInterval(Interval * 2);
            }
            //SendingEmailInfo.Remove(emailInfo);
        }