示例#1
0
        private void inportSmtpList(object o)
        {
            int totals = 0; int success = 0;

            WriteLog("");
            WriteLog("正在读取数据.....");
            IList <string> data = FileDirectory.FileRead(fileName, FileDirectory.FileEncoding(fileName));

            totals = data.Count;
            WriteLog("读取到:" + totals + " 行记录!");

            WriteLog("正在导入数据.....");
            int index = 1;
            int port  = 25;

            foreach (string str in data)
            {
                string[] list = str.Split(',');
                if (list.Length != 3)
                {
                    WriteLog("第" + index.ToString() + "行数据格式不正确:" + str);
                }
                else
                {
                    string smtp     = list[0].Trim();
                    string userName = list[1].Trim();

                    if (!IsSmtp(smtp))
                    {
                        WriteLog("第" + index.ToString() + "行Smtp服务器地址格式不正确:" + str);
                    }
                    else
                    {
                        if (SmtpListHelper.IsExistByID(smtp, port, userName))
                        {
                            WriteLog("第" + index.ToString() + "行数据已存在:" + str);
                        }
                        else
                        {
                            //bool isTrue = NetHelper.CheckSMTP(list[1], list[2], list[0]);
                            //if (isTrue) {
                            SmtpList info = new SmtpList();
                            info.SmtpServer = list[0];
                            info.UserName   = list[1];
                            info.SPassword  = list[2];
                            info.SmtpPort   = 25;
                            info.CreateTime = DateTime.Now.ToDateTime().ToDateTime();
                            SmtpListHelper.Insert(info);
                            success++;
                            //} else {
                            //    WriteLog("第" + index.ToString() + "行SMTP无法连接到服务器,请检查用户名和密码是否正确和账号是否被封:" + str);
                            //}
                        }
                    }
                }
                index++;
            }
            SmtpListHelper.ClearCacheAll();
            WriteLog("导入Smtp服务器列表完成:共 {0} 条记录,成功 {1} 条记录,失败 {2} 条记录!".FormatWith(totals, success, totals - success));
        }
示例#2
0
        private void mnuDeleteAll_Click(object sender, EventArgs e)
        {
            switch (type)
            {
            case 1:
                if (MessageBox.Show("确认要删除全部记录吗?", " 系统提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                {
                    int rows = new SQL().Database("ConnString").Delete(EmailList._).ToExec();
                    EmailListHelper.ClearCacheAll();
                    BindData();
                }
                break;

            case 2:
                if (MessageBox.Show("确认要删除全部记录吗?", " 系统提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                {
                    int rows = new SQL().Database("ConnString").Delete(SmtpList._).ToExec();
                    SmtpListHelper.ClearCacheAll();
                    BindData();
                }
                break;

            case 3:
                if (MessageBox.Show("确认要删除全部记录吗?", " 系统提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                {
                    int rows = new SQL().Database("ConnString").Delete(IpHistory._).ToExec();
                    IpHistoryHelper.ClearCacheAll();
                    BindData();
                }
                break;
            }
        }
示例#3
0
 public static void Delete(string[] args, bool exit = false)
 {
     if (args.Length == 2)
     {
         args = (string.Join(" ", args) + " *").Split(" ");
     }
     if (args[1].Trim().ToLower() == "smtp")
     {
         WriteLog("delete(d) smtp * 删除SMTP数据");
     }
     if (args[1].Trim().ToLower() == "email")
     {
         WriteLog("delete(d) email * 删除邮箱数据");
     }
     WriteLog("===============================================================================");
     if (args[1].Trim().ToLower() == "smtp")
     {
         args = string.Join(" ", args, 2, args.Length - 2).Split(' ');
         int len = 0;
         if (args.Length == 1 && args [0] == "*")
         {
             len = new SQL().Delete(SmtpList._).ToExec();
         }
         else
         {
             foreach (string s in args)
             {
                 string[] ss = s.Split(',');
                 if (ss.Length != 3)
                 {
                     continue;
                 }
                 len += SmtpListHelper.DeleteByID(ss[0], ss[1].ToInt(25), ss[2]) ? 1 : 0;
             }
         }
         WriteLog("删除影响行数:{0}", len);
         SmtpListHelper.ClearCacheAll();
     }
     else if (args[1].Trim().ToLower() == "email")
     {
         args = string.Join(" ", args, 2, args.Length - 2).Split(' ');
         int len = 0;
         if (args.Length == 1 && args [0] == "*")
         {
             len = new SQL().Delete(EmailList._).ToExec();
         }
         else
         {
             foreach (string s in args)
             {
                 len += EmailListHelper.DeleteByID(s) ? 1 : 0;
             }
         }
         WriteLog("删除影响行数:{0}", len);
         EmailListHelper.ClearCacheAll();
     }
     WriteLog("END");
     Input(exit);
 }
示例#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 mnuDelete_Click(object sender, EventArgs e)
        {
            switch (type)
            {
            case 1:
                if (listView1.CheckedItems.Count == 0)
                {
                    MessageBox.Show("请选择你要删除的记录!", " 系统提示");
                    return;
                }
                if (MessageBox.Show("确认要删除选中的记录吗?", " 系统提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                {
                    IList <string> data = new List <string>();
                    foreach (ListViewItem item in listView1.Items)
                    {
                        if (item.Checked)
                        {
                            data.Add(item.Tag.ToString());
                        }
                    }
                    int rows = new SQL().Database("ConnString").Delete(EmailList._)
                               .Where(new Where()
                                      .And(EmailList._EmailAddress, "('" + data.Select(p => p.SafeSql()).Join("','") + "')", Operator.In)
                                      ).ToExec();

                    EmailListHelper.ClearCacheAll();
                    BindData();
                }
                break;

            case 2:
                if (listView1.CheckedItems.Count == 0)
                {
                    MessageBox.Show("请选择你要删除的记录!", " 系统提示");
                    return;
                }

                if (MessageBox.Show("确认要删除选中的记录吗?", " 系统提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                {
                    foreach (ListViewItem item in listView1.Items)
                    {
                        if (item.Checked)
                        {
                            string[] list = item.Tag.ToString().Split(',');

                            string id       = list[0].ToString();
                            int    port     = list[1].ToString().ToInt(25);
                            string username = list[2].ToString();
                            string password = list[3].ToString();
                            SmtpListHelper.DeleteByID(id, port, username, password);
                        }
                    }
                    SmtpListHelper.ClearCacheAll();
                    BindData();
                }
                break;
            }
        }
示例#6
0
 private void UpdateSmtpListSendCount(int smtpIndex, int smtps, int smtps2)
 {
     smtpList[smtpIndex].Sends     += smtps;
     smtpList[smtpIndex].SendFails += smtps2;
     smtpInfo.Sends      = smtpList[smtpIndex].Sends;
     smtpInfo.SendFails  = smtpList[smtpIndex].SendFails;
     smtpInfo.CreateTime = null;
     SmtpListHelper.Update(smtpInfo);
 }
示例#7
0
        /// <summary>
        /// 开始群发邮件
        /// </summary>
        private void sendStart()
        {
            UpdateSendSettingStatus(1);             //开始发送并初始化数据

            smtpList = SmtpListHelper.SelectListByAll().Where(p => p.Status == 0).ToList();
            if (smtpList.Count == 0)
            {
                WriteLog("SMTP列表为空!"); if (uiDone != null)
                {
                    uiDone();
                }
                return;
            }
            smtpInfo = smtpList[0];             //默认使用第一个SMTP发送

            template = templateList.Where(t => t.TemplateID == sendSetting.TemplateID).FirstOrDefault();
            if (template.IsNull() || template.TemplateID.IsNull())
            {
                WriteLog("找不到模版ID:" + sendSetting.TemplateID); if (uiDone != null)
                {
                    uiDone();
                }
                return;
            }

            WriteLog("");
            WriteLog(template.Subject + "|" + NetHelper.GetNetName(sendSetting.ConnectType.Value) + "|" + smtpInfo.SmtpServer + "|" + smtpInfo.UserName + " 开始发送!");

            email = new Email(smtpInfo.SmtpServer, smtpInfo.SmtpPort.Value)
                    .Ssl(smtpInfo.SSL.Value)
                    .Credentials(smtpInfo.UserName, smtpInfo.SPassword)
                    .IsBodyHtml(template.IsHTML.Value)
                    .Timeout(3000);

            int state = SendEmails();

            if (state == -1)
            {
                return;                          //停止发送邮件
            }
            if (state == 0)
            {
                UpdateSendSettingStatus(2);                         //正常发送完成时 标记全部发送完成
            }
            WriteLog(template.Subject + (state == 0 ? " 已发送完成!" : " 已停止发送!"));

            //此处可邮件通知

            if (uiDone != null)
            {
                uiDone();
            }

            clear();             //清理数据
        }
示例#8
0
        public static void Smtps(bool exit = false)
        {
            WriteLog("smtps(ss) 显示SMTP列表");
            WriteLog("===============================================================================");
            IList <SmtpList> smtpList = SmtpListHelper.SelectListByAll();

            foreach (var smtp in smtpList)
            {
                WriteLog("{0},{1},{2}", smtp.SmtpServer, smtp.SmtpPort, smtp.UserName);
            }
            WriteLog("count:{0}", smtpList.Count);
            WriteLog("END");
            Input(exit);
        }
示例#9
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();
        }
示例#10
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.txtSmtpServer.Text))
            {
                MessageBox.Show("SMTP服务器不能为空", "系统提示");
                return;
            }
            if (string.IsNullOrEmpty(this.txtSmtpPort.Text))
            {
                MessageBox.Show("SMTP服务器端口不能为空", "系统提示");
                return;
            }
            if (string.IsNullOrEmpty(this.txtUserName.Text))
            {
                MessageBox.Show("登录用户名不能为空", "系统提示");
                return;
            }

            SmtpList info = new SmtpList();

            info.SmtpServer = this.txtSmtpServer.Text;
            info.SmtpPort   = this.txtSmtpPort.Text.ToInt(25);
            info.UserName   = this.txtUserName.Text;
            info.SPassword  = this.txtSPassword.Text;
            info.SSL        = this.checkBoxSSL.Checked;
            info.Status     = this.checkBoxStatus.Checked == true ? 0 : 1;

            //bool isTrue = NetHelper.CheckSMTP(info.UserName, info.SPassword, info.SmtpServer);
            //if (!isTrue) {
            //    MessageBox.Show("无法连接SMTP服务器,请检查用户名和密码是否正确和账号是否被封。", " 系统提示");
            //    return;
            //}

            DialogResult = System.Windows.Forms.DialogResult.OK;

            if (!smtp.IsNullEmpty() || SmtpListHelper.IsExistByID(info.SmtpServer, info.SmtpPort.Value, info.UserName))
            {
                SmtpListHelper.Update(info);
            }
            else
            {
                info.CreateTime = DateTime.Now.ToDateTime().ToDateTime();
                SmtpListHelper.Insert(info);
            }
            SmtpListHelper.ClearCacheAll();

            MessageBox.Show("保存数据成功!", " 系统提示");
            this.Close();
        }
示例#11
0
        private void mnuSearch_Click(object sender, EventArgs e)
        {
            switch (type)
            {
            case 1:
                EmailListHelper.ClearCacheAll();
                break;

            case 2:
                SmtpListHelper.ClearCacheAll();
                break;

            case 3:
                IpHistoryHelper.ClearCacheAll();
                break;
            }
            BindData();
        }
示例#12
0
        private void LoadEditData()
        {
            SmtpList info = SmtpListHelper.SelectByID(smtp, port, user);

            if (info.IsNull() || info.SmtpServer.IsNull())
            {
                return;
            }
            txtSmtpServer.Text     = info.SmtpServer.ToString();
            txtSmtpPort.Text       = info.SmtpPort.ToString();
            txtUserName.Text       = info.UserName.ToString();
            txtSPassword.Text      = info.SPassword.ToString();
            checkBoxSSL.Checked    = info.SSL == true ? true : false;
            checkBoxStatus.Checked = info.Status == 0 ? true : false;

            txtSmtpServer.Enabled = false;
            txtSmtpPort.Enabled   = false;
            txtUserName.Enabled   = false;
        }
示例#13
0
        private void mnuDisable_Click(object sender, EventArgs e)
        {
            switch (type)
            {
            case 1:
                EmailListHelper.ClearCacheAll();
                break;

            case 2:
                SmtpListHelper.ClearCacheAll();
                foreach (ListViewItem item in listView1.Items)
                {
                    if (item.Checked)
                    {
                        string[] list = item.Tag.ToString().Split(',');

                        SmtpList info = new SmtpList();
                        info.SmtpServer = list[0].ToString();
                        info.SmtpPort   = list[1].ToString().ToInt(25);
                        info.UserName   = list[2].ToString();
                        info.SPassword  = list[3].ToString();
                        info.Status     = 1;
                        SmtpListHelper.Update(info);
                        //if (!info.SmtpServer.IsNullEmpty() || SmtpListHelper.IsExistByID(info.SmtpServer, info.SmtpPort.Value, info.UserName)) {
                        //    SmtpListHelper.Update(info);
                        //}
                    }
                }
                break;

            case 3:
                IpHistoryHelper.ClearCacheAll();
                break;
            }
            BindData();
        }
示例#14
0
        private void BindData()
        {
            long   totals    = 0;
            string strStatus = this.toolStripComboBox1.Text.Trim();

            ThreadPool.QueueUserWorkItem(new WaitCallback((o) => {
                switch (type)
                {
                case 1:
                    Where where = null;
                    switch (strStatus)
                    {
                    case "等待发送":
                        where = new Where().And("LastSendStatus", 0, Operator.Equal);
                        break;

                    case "发送成功":
                        where = new Where().And("LastSendStatus", 1, Operator.Equal);
                        break;

                    case "发送失败":
                        where = new Where().And("LastSendStatus", 2, Operator.Equal);
                        break;

                    default:
                        where = null;
                        break;
                    }
                    IList <EmailList> emailList = EmailListHelper.SelectPageList(page, pageSize, out totals, "", where);

                    pages = (int)(totals / pageSize + (totals % pageSize == 0 ? 0 : 1));

                    EmailListobj obj1 = new EmailListobj();
                    obj1.list         = emailList;
                    obj1.page         = page;
                    obj1.pages        = pages;
                    obj1.totals       = totals;

                    this.Invoke(new CallFormInThread(loadData), obj1);

                    break;

                case 2:
                    IList <SmtpList> smtpList = SmtpListHelper.SelectPageList(page, pageSize, out totals);
                    pages = (int)(totals / pageSize + (totals % pageSize == 0 ? 0 : 1));

                    SmtpListobj obj2 = new SmtpListobj();
                    obj2.list        = smtpList;
                    obj2.page        = page;
                    obj2.pages       = pages;
                    obj2.totals      = totals;

                    this.Invoke(new CallFormInThread(loadData), obj2);

                    break;

                case 3:
                    IList <IpHistory> ipList = IpHistoryHelper.SelectPageList(page, pageSize, out totals);

                    pages             = (int)(totals / pageSize + (totals % pageSize == 0 ? 0 : 1));
                    IpHistoryobj obj3 = new IpHistoryobj();
                    obj3.list         = ipList;
                    obj3.page         = page;
                    obj3.pages        = pages;
                    obj3.totals       = totals;

                    this.Invoke(new CallFormInThread(loadData), obj3);
                    break;
                }
            }), null);
        }