Exemple #1
0
        public bool Send()
        {
            Log.Info("=====开始发送群发邮件=====");
            DataAccess.Tnsmtp_EmailCollection tnsmtp_EmailCollection = new DataAccess.Tnsmtp_EmailCollection();

            Log.Info("开始查询群发数据");
            if (!tnsmtp_EmailCollection.ListSendByFlagStatus((int)EmailFlagStatus.群发))
            {
                Log.Info("查询群发件失败");
                Alert("查询群发件失败!");
                return(false);
            }
            int sendcount = tnsmtp_EmailCollection.DataTable.Rows.Count;

            Log.Info("群发邮件数量:" + sendcount);
            if (sendcount == 0)
            {
                Log.Info("没有群发邮件");
                Alert("没有群发邮件");
                return(true);
            }


            Log.Info("开始遍历数据");

            foreach (DataRow dr in tnsmtp_EmailCollection.DataTable.Rows)
            {
                int mailid = int.Parse(dr[Tnsmtp_Email._MAIL_ID].ToString());

                DataAccess.Tnsmtp_Email tnsmtp_Email = new Tnsmtp_Email();
                Log.Info("开始查询邮件内容!");
                if (!tnsmtp_Email.SelectByPK(mailid))
                {
                    Log.Info("异常,邮件不存在!");
                    Alert("邮件不存在");
                    return(false);
                }
                Log.Info("创建发送对象!");
                GroupSendFacade send = new GroupSendFacade();
                if (!send.SendEmail(dr))
                {
                    Log.Info("SendFacade 发送失败,修改发送状态======================" + tnsmtp_Email.Inmail);
                    tnsmtp_Email.FlagStatus = (int)EmailFlagStatus.发送失败;
                    tnsmtp_Email.Senddate   = DateTime.Now;
                    tnsmtp_Email.Remarks    = send.PromptInfo.Message;

                    if (!tnsmtp_Email.Update())
                    {
                        Log.Info("修改发送状态失败");
                        Alert("修改发送状态失败!");
                        return(false);
                    }
                    continue;
                }

                Log.Info("SendFacade发送成功!,开始修改发送状态");

                tnsmtp_Email.FlagStatus = (int)EmailFlagStatus.已发送;
                tnsmtp_Email.Senddate   = DateTime.Now;
                if (!tnsmtp_Email.Update())
                {
                    Log.Info("修改发送状态失败");
                    Alert("修改发送状态失败!");
                    return(false);
                }

                Thread.Sleep(10000);  //降低发件频率
            }

            Log.Info("=====结束发送群发邮件=====");
            return(true);
        }
Exemple #2
0
        public bool Send()
        {
            //防止并发加锁


            Log.Info("=====开始发送定时邮件=====");
            DataAccess.Tnsmtp_EmailCollection tnsmtp_EmailCollection = new DataAccess.Tnsmtp_EmailCollection();


            if (!tnsmtp_EmailCollection.ListSendByFlagStatus((int)EmailFlagStatus.定时邮件))
            {
                Log.Info("查询定时邮件失败");
                Alert("查询定时邮件失败!");
                return(false);
            }

            if (tnsmtp_EmailCollection.DataTable.Rows.Count == 0)
            {
                Log.Info("没有定时邮件");
                Alert("没有定时邮件");
                return(true);
            }

            Log.Info("需要发送邮件数量:" + tnsmtp_EmailCollection.DataTable.Rows.Count);

            foreach (DataRow dr in tnsmtp_EmailCollection.DataTable.Rows)
            {
                DateTime sendtime = new DateTime();
                if (!DateTime.TryParse(dr[Tnsmtp_Email._SENDDATE].ToString(), out sendtime))
                {
                    Log.Info("发送时间为空");
                    continue;
                }

                int mailid = int.Parse(dr[Tnsmtp_Email._MAIL_ID].ToString());

                Log.Info("发送时间" + sendtime + "***");

                if (DateTime.Compare(DateTime.Now, sendtime) < 0)
                {
                    Log.Info("没到发送时间,继续等待:" + mailid + "***" + sendtime);
                    continue;
                }

                Log.Info("准备发送邮件:" + mailid + "***");


                DataAccess.Tnsmtp_Email tnsmtp_Email = new Tnsmtp_Email();
                GroupSendFacade         send         = new GroupSendFacade();
                if (!send.SendEmail(dr))
                {
                    Log.Info("发送邮件失败:" + mailid + "***");
                    tnsmtp_Email.FlagStatus = (int)EmailFlagStatus.发送失败;
                    tnsmtp_Email.Senddate   = DateTime.Now;
                    if (!tnsmtp_Email.Update())
                    {
                        Log.Info("修改发送状态失败");
                        Alert("修改发送状态失败!");
                        return(false);
                    }

                    continue;
                }

                if (!tnsmtp_Email.SelectByPK(mailid))
                {
                    Log.Info("异常,邮件不存在!");
                    Alert("邮件不存在");
                    return(false);
                }

                tnsmtp_Email.FlagStatus = (int)EmailFlagStatus.已发送;
                tnsmtp_Email.Senddate   = DateTime.Now;
                if (!tnsmtp_Email.Update())
                {
                    Log.Info("修改发送状态失败");
                    Alert("修改发送状态失败!");
                    return(false);
                }
            }

            Log.Info("=====结束发送定时邮件=====");
            return(true);
        }