예제 #1
0
        private void mnuEdit_Click(object sender, EventArgs e)
        {
            SendSetting setting = SendSettingHelper.SelectByID(1);

            if (setting.IsNull() || setting.TemplateID.IsNull())
            {
                return;
            }

            if (setting.TemplateID == lastID && !this.checkBoxStatus.Checked)
            {
                MessageBox.Show("发送邮件设置使用了此模板,该模板不能不可用", "系统提示");
                return;
            }

            tabControl1.SelectedTab = tabControl1.TabPages[0];
            if (currentIndex < 0 || lastID < 1)
            {
                return;
            }
            HtmlTemplate info = new HtmlTemplate();

            info.Subject    = this.txtSubject.Text;
            info.Body       = this.txtBody.Text;
            info.IsHTML     = this.checkBoxIsHTML.Checked ? true : false;
            info.Status     = this.checkBoxStatus.Checked ? 0 : 1;
            info.ShowName   = this.txtShowName.Text;
            info.TemplateID = lastID;
            HtmlTemplateHelper.Update(info);
            dataGridView.Rows[currentIndex].Cells[1].Value = info.Subject;
            HtmlTemplateHelper.ClearCacheAll();
            MessageBox.Show("保存成功", "系统提示");
        }
예제 #2
0
        public static void Resend(bool exit = false)
        {
            WriteLog("resend(rs) 重新发送邮件");
            WriteLog("===============================================================================");
            SendSettingHelper.Update(new SendSetting()
            {
                SettingID = 1, Status = 0
            });
            SendSettingHelper.ClearCacheSelectByID(1);

            new SQL()
            .Update(EmailList._)
            .Set(EmailList._LastSendStatus, 0)
            .Set(EmailList._LastSendError, "")
            .Set(EmailList._LastSendTime, null, true)
            .Set(EmailList._LastSendSmtp, "")
            .Set(EmailList._SendCount, 0)
            .ToExec();

            new SQL().Update(SmtpList._)
            .Set(SmtpList._Sends, 0)
            .Set(SmtpList._SendFails, 0)
            .ToExec();

            MailerCenter.Start((msg) => {
                msg = "[{0}]-{1}".FormatWith(DateTime.Now.ToDateTimeFFF(), msg);
                WriteLog(msg);
            }, () => { WriteLog("END"); if (exit)
                       {
                           System.Environment.Exit(0);
                       }
                       Console.Write("> "); });
            Parse(Console.ReadLine());
        }
예제 #3
0
        private void mnuDelete_Click(object sender, EventArgs e)
        {
            if (dataGridView.Rows.Count == 0 || lastID < 1)
            {
                return;
            }

            SendSetting setting = SendSettingHelper.SelectByID(1);

            if (setting.IsNull() || setting.TemplateID.IsNull())
            {
                return;
            }

            if (setting.TemplateID == lastID && !this.checkBoxStatus.Checked)
            {
                MessageBox.Show("发送邮件设置使用了此模板,该模板不能删除", "系统提示");
                return;
            }

            if (MessageBox.Show("是否删除此邮件模板?", " 系统提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.OK)
            {
                HtmlTemplateHelper.DeleteByID(lastID);
                HtmlTemplateHelper.ClearCacheAll();
                dataGridView.Rows.RemoveAt(currentIndex);
                getRowData();
            }
            tabControl1.SelectedTab = tabControl1.TabPages[0];
        }
예제 #4
0
 /// <summary>
 /// 清理缓存
 /// </summary>
 private void clear()
 {
     SmtpListHelper.ClearCacheAll(); smtpList         = null;
     EmailListHelper.ClearCacheAll(); emailList       = null;
     SendSettingHelper.ClearCacheAll(); sendSetting   = null;
     HtmlTemplateHelper.ClearCacheAll(); templateList = null;
     IpHistoryHelper.ClearCacheAll();
 }
예제 #5
0
        private void UpdateSendSettingStatus(int status)
        {
            SendSetting setting = new SendSetting();

            setting.SettingID = sendSetting.SettingID;
            setting.Status    = status;
            SendSettingHelper.Update(setting);
        }
예제 #6
0
        private void mnuEdit_Click(object sender, EventArgs e)
        {
            if (this.cboTemplate.SelectedIndex < 0)
            {
                MessageBox.Show("发送主题为空,保存失败", "系统提示");
                return;
            }
            SendSetting info = new SendSetting();

            info.TemplateID     = (long)this.cboTemplate.SelectedValue;
            info.ConnectType    = rdoRoute.Checked ? 0 : rdoModel.Checked ? 1 : 2;
            info.IPInterval     = txtIPInterval.Text == "0" ? 0 : txtIPInterval.Text.ToInt(1000);
            info.SendInterval   = txtSendInterval.Text.ToInt(10);
            info.SmtpInterval   = txtSmtpInterval.Text == "0" ? 0 : txtSmtpInterval.Text.ToInt(20);
            info.Status         = this.cboStatus.SelectedValue.ToString().ToInt(0);
            info.MaxRetryCount  = txtMaxRetryCount.Text.ToInt(10);
            info.SendRetryCount = txtSendRetryCount.Text.ToInt(10);
            info.DeleteInterval = txtDeleteInterval.Text.ToInt(60);

            if (sendSetting.IsNull() || sendSetting.SettingID.IsNull())
            {
                info.SettingID = 1;
                SendSettingHelper.Insert(info);
            }
            else
            {
                info.SettingID = sendSetting.SettingID;
                SendSettingHelper.Update(info);
            }
            SendSettingHelper.ClearCacheAll();

            if (info.Status == 0 && (int)cboStatus.Tag != info.Status)
            {
                new SQL()
                .Update(EmailList._)
                .Set("LastSendStatus", 0)
                .Set("LastSendError", "")
                .Set("LastSendTime", null, true)
                .Set("LastSendSmtp", "")
                .Set("SendCount", 0)
                .ToExec();

                new SQL().Update(SmtpList._)
                .Set("Sends", 0)
                .Set("SendFails", 0)
                .ToExec();

                new SQL().Delete(IpHistory._)
                .ToExec();
            }

            MessageBox.Show("保存数据成功!", " 系统提示");
            this.Close();
        }
예제 #7
0
        private void frmSendSetting_Activated(object sender, EventArgs e)
        {
            frmMain.Instance.ShowStatusText("正在数据....");
            HtmlTemplateHelper.ClearCacheAll();
            cboTemplate.DataSource    = null;;
            cboTemplate.ValueMember   = "TemplateID";
            cboTemplate.DisplayMember = "Subject";
            cboTemplate.DataSource    = HtmlTemplateHelper.SelectListByAll().Where(p => p.Status == 0).OrderByDescending(p => p.TemplateID).Select(p => new { p.TemplateID, p.Subject }).ToDataTable();

            DataTable dt = new DataTable()
                           .AddColumn <int>("id")
                           .AddColumn <string>("name")
                           .AddRow(0, "等待发送")
                           .AddRow(1, "正在发送")
                           .AddRow(2, "已发送完成");

            this.cboStatus.DataSource    = dt;
            this.cboStatus.DisplayMember = "name";
            this.cboStatus.ValueMember   = "id";
            this.cboStatus.SelectedIndex = 0;

            sendSetting = SendSettingHelper.SelectByID(1);
            if (sendSetting.IsNull() || sendSetting.SettingID.IsNull())
            {
                return;
            }

            cboTemplate.SelectedValue = sendSetting.TemplateID;
            if (sendSetting.ConnectType == 0)
            {
                rdoRoute.Checked = true;
            }
            if (sendSetting.ConnectType == 1)
            {
                rdoModel.Checked = true;
            }
            if (sendSetting.ConnectType == 2)
            {
                rdoTY.Checked = true;
            }
            txtIPInterval.Text      = sendSetting.IPInterval.ToString();
            txtSendInterval.Text    = sendSetting.SendInterval.ToString();
            txtSmtpInterval.Text    = sendSetting.SmtpInterval.ToString();
            txtMaxRetryCount.Text   = sendSetting.MaxRetryCount.ToString();
            txtDeleteInterval.Text  = sendSetting.DeleteInterval.ToString();
            txtSendRetryCount.Text  = sendSetting.SendRetryCount.ToString();
            cboStatus.SelectedValue = sendSetting.Status;
            cboStatus.Tag           = sendSetting.Status.Value;
            frmMain.Instance.ShowStatusText("数据加载完成!");
        }
예제 #8
0
        /// <summary>
        /// 开始群发邮件
        /// </summary>
        /// <param name="msg">通知消息</param>
        /// <param name="done">完成执行</param>
        public void Start(Action <string> msg = null, Pub.Class.Action done = null)
        {
            exit   = false;
            uiMsg  = msg; uiDone = done;
            thread = new Thread(() => {
                smtpList     = SmtpListHelper.SelectListByAll();
                sendSetting  = SendSettingHelper.SelectByID(1);
                templateList = HtmlTemplateHelper.SelectListByAll().Where(p => p.Status == 0).ToList();

                sendStart();
            });
            thread.IsBackground = true;
            thread.Start();
        }
예제 #9
0
        public static void Config(bool exit = false)
        {
            WriteLog("config(c) 显示发送配置");
            WriteLog("===============================================================================");
            SendSetting          sendSetting  = SendSettingHelper.SelectByID(1);
            IList <HtmlTemplate> templateList = HtmlTemplateHelper.SelectListByAll();

            WriteLog("邮件模版:{0}", templateList.Where(p => p.TemplateID == sendSetting.TemplateID).FirstOrDefault().IfNull(new HtmlTemplate()).Subject ?? "无");
            WriteLog("网络连接类型:{0}", NetHelper.GetNetName(sendSetting.ConnectType.Value));
            WriteLog("发送邮件时间间隔(毫秒):{0}", sendSetting.SendInterval);
            WriteLog("发送多少封邮件后更换IP:{0}", sendSetting.IPInterval == 0 ? "0不更换IP" : sendSetting.IPInterval.ToString());
            WriteLog("发送多少封邮件后更换SMTP:{0}", sendSetting.SmtpInterval == 0 ? "0不更换SMTP" : sendSetting.SmtpInterval.ToString());
            WriteLog("清理多少分钟之前的历史IP:{0}", sendSetting.DeleteInterval);
            WriteLog("检测网络连接重试次数:{0}", sendSetting.MaxRetryCount);
            WriteLog("发送邮件失败重试次数:{0}", sendSetting.SendRetryCount);
            WriteLog("发送状态:{0}", sendSetting.Status == 0 ? "等待发送" : sendSetting.Status == 1 ? "正在发送" : "已发送完成");
            WriteLog("-------------------------------------------------------------------------------");
            WriteLog("可用邮箱数量:{0}".FormatWith(new SQL().From(EmailList._).Count(EmailList._EmailAddress).ToScalar().ToString()));
            WriteLog("可用SMTP数量:{0}".FormatWith(new SQL().From(SmtpList._).Count(SmtpList._SmtpServer).ToScalar().ToString()));
            WriteLog("END");
            Input(exit);
        }
예제 #10
0
        public static void SetConfig(string[] args, bool exit = false)
        {
            if (args.Length != 3)
            {
                Input(exit);
            }
            string cmd   = args[1].Trim().ToLower();
            int    value = args[2].ToInt();

            if (setDic.ContainsKey(cmd))
            {
                WriteLog("sc {0} {1} 修改发送配置".FormatWith(cmd, value));
                WriteLog("===============================================================================");
                int result = new SQL().Update(SendSetting._).Set(setDic[cmd], value).ToExec();
                WriteLog(result > 0 ? "操作成功!" : "操作失败!");
                if (result > 0)
                {
                    SendSettingHelper.ClearCacheSelectByID(1);
                }
            }
            WriteLog("END");
            Input(exit);
        }
예제 #11
0
        /// <summary>
        /// 更换IP
        /// </summary>
        /// <param name="netType">0表示路由 1表示拨号连接</param>
        /// <param name="msg">通知输出消息</param>
        /// <param name="done">完成时执行</param>
        /// <param name="index">第几次执行</param>
        /// <returns></returns>
        public static string ChangeIP(int netType, Action <string> msg = null, Pub.Class.Action done = null, int index = 0)
        {
            string name = GetNetName(netType);

            setting = SendSettingHelper.SelectByID(1);

            if (setting.IsNull())
            {
                if (!msg.IsNull())
                {
                    msg("请修改发送设置!");
                }
                if (!done.IsNull())
                {
                    done();
                }
                return("");
            }
            else
            {
                if (index == setting.MaxRetryCount)
                {
                    if (!done.IsNull())
                    {
                        done();
                    }
                    return("");
                }
                if (!msg.IsNull())
                {
                    msg((index + 1).ToString());
                }

                //清空多少分钟前的历史IP
                if (Data.Pool("ConnString").DBType == "SqlServer")
                {
                    "delete from IpHistory where CreateTime < DateAdd(MINUTE , -{0}, getdate())".FormatWith(setting.DeleteInterval).ToSQL().ToExec();
                }
                else if (Data.Pool("ConnString").DBType == "SQLite" || Data.Pool("ConnString").DBType == "MonoSQLite")
                {
                    "delete from IpHistory where datetime(CreateTime) < datetime('now','localtime', '-{0} minute')".FormatWith(setting.DeleteInterval).ToSQL().ToExec();
                }
                if (!msg.IsNull())
                {
                    msg("正在重启" + name + "......");
                }
                IController connect;
                switch (netType)
                {
                case 1: connect = new ModelController(); break;

                case 2: connect = new TianYiController(); break;

                default: connect = new RouteController(); break;
                }
                string error = connect.Reset();
                if (!error.IsNullEmpty())
                {
                    if (!msg.IsNull())
                    {
                        msg("重启" + name + "失败:" + error);
                    }
                    return(ChangeIP(netType, msg, done, index + 1));
                }
                else
                {
                    if (!msg.IsNull())
                    {
                        msg("已重启" + name + ",正在检测是否联网......");
                    }
                    bool isTrue = NetHelper.CheckNetwork(msg);
                    if (!isTrue)
                    {
                        return(ChangeIP(netType, msg, done, index + 1));
                    }

                    if (!msg.IsNull())
                    {
                        msg("已联接网络,正在获取IP......");
                    }
                    string ip = IPHelper.GetIpFast();

                    if (!msg.IsNull())
                    {
                        msg("获取到IP:" + ip);
                    }
                    if (IpHistoryHelper.IsExistByID(ip))
                    {
                        if (!msg.IsNull())
                        {
                            msg("检测到IP:" + ip + "最近已使用!");
                        }
                        return(ChangeIP(netType, msg, done, index + 1));
                    }
                    else
                    {
                        IpHistoryHelper.Insert(new IpHistory()
                        {
                            IP = ip, CreateTime = DateTime.Now.ToDateTime().ToDateTime()
                        });
                    };
                    return(ip);
                }
            }
        }