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; } }
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); }
/// <summary> /// 清理缓存 /// </summary> private void clear() { SmtpListHelper.ClearCacheAll(); smtpList = null; EmailListHelper.ClearCacheAll(); emailList = null; SendSettingHelper.ClearCacheAll(); sendSetting = null; HtmlTemplateHelper.ClearCacheAll(); templateList = null; IpHistoryHelper.ClearCacheAll(); }
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; } }
private void inportEmailList() { 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; foreach (string str in data) { string[] list = str.Split(','); string email = list[0].Trim(); if (!email.IsEmail()) { WriteLog("第" + index.ToString() + "行Email地址格式不正确:" + str); } else { if (EmailListHelper.IsExistByID(email)) { WriteLog("第" + index.ToString() + "行数据已存在:" + str); } else { EmailList info = new EmailList(); info.EmailAddress = email; info.NickName = email.Split('@')[0]; if (list.Length == 10) { info.ex0 = list[1]; info.ex1 = list[2]; info.ex2 = list[3]; info.ex3 = list[4]; info.ex4 = list[5]; info.ex5 = list[6]; info.ex6 = list[7]; info.ex7 = list[8]; info.ex8 = list[9]; } info.CreateTime = DateTime.Now.ToDateTime().ToDateTime(); EmailListHelper.Insert(info); success++; } } index++; } EmailListHelper.ClearCacheAll(); WriteLog("导入Email列表完成:共 {0} 条记录,成功 {1} 条记录,失败 {2} 条记录!".FormatWith(totals, success, totals - success)); }
public void loadData() { long totals = 0; Where where = null; IList <EmailList> emailList = EmailListHelper.SelectPageList(winFormPager1.CurrentPage, winFormPager1.PageSize, out totals, "", where); pages = (int)(totals / winFormPager1.PageSize + (totals % winFormPager1.PageSize == 0 ? 0 : 1)); dbGridView1.Rows.Clear(); //清空列表数据 winFormPager1.RecordCount = totals; //设置分页控件记录总行数为接口返回的记录总数 dbGridView1.BeginInvoke(new Pub.Class.Action(() => { emailList.Do((p, i) => { dbGridView1.Rows.Add(p.EmailAddress.ToString(), p.NickName, "修改"); }); })); }
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(); }
private void button1_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(this.txtEmailAddress.Text)) { MessageBox.Show("发送的Email不能为空", "系统提示"); return; } DialogResult = System.Windows.Forms.DialogResult.OK; EmailList info = new EmailList(); info.EmailAddress = this.txtEmailAddress.Text; info.NickName = this.txtNickName.Text; if (info.NickName.IsNullEmpty()) { info.NickName = info.EmailAddress.Split('@')[0]; } info.ex0 = this.txtex0.Text; info.ex1 = this.txtex1.Text; info.ex2 = this.txtex2.Text; info.ex3 = this.txtex3.Text; info.ex4 = this.txtex4.Text; info.ex5 = this.txtex5.Text; info.ex6 = this.txtex6.Text; info.ex7 = this.txtex7.Text; info.ex8 = this.txtex8.Text; info.LastSendError = txtError.Text; //info.LastSendStatus = this.checkBoxStatus.Checked ? 0 : 1; if (!email.IsNullEmpty() || EmailListHelper.IsExistByID(info.EmailAddress)) { EmailListHelper.Update(info); } else { info.CreateTime = DateTime.Now.ToDateTime().ToDateTime(); EmailListHelper.Insert(info); } EmailListHelper.ClearCacheAll(); MessageBox.Show("保存数据成功!", " 系统提示"); this.Close(); }
private void exportEmailList(object o) { string fileName = (string)o; var emailList = EmailListHelper.SelectListByAll(); StringBuilder sb = new StringBuilder(); if (FileDirectory.FileExists(fileName)) { FileDirectory.FileDelete(fileName); } emailList.Do(p => { if (p.LastSendError.IndexOf("Mailbox not found") == -1) { sb.AppendLine(p.EmailAddress); } }); FileDirectory.FileWrite(fileName, sb.ToString(), Encoding.UTF8); }
public static void Emails(bool exit = false) { WriteLog("emails(es) 显示邮箱列表"); WriteLog("==============================================================================="); int count = new SQL().From(EmailList._).Count(EmailList._EmailAddress).ToScalar().ToString().ToInt(); if (count > 100) { WriteLog("数据太多不显示!"); WriteLog("count:{0}", count); } else { IList <EmailList> emailList = EmailListHelper.SelectListByAll(); foreach (var email in emailList) { WriteLog(email.EmailAddress); } WriteLog("count:{0}", emailList.Count); } WriteLog("END"); Input(exit); }
private void LoadEditData() { EmailList info = EmailListHelper.SelectByID(email); if (info.IsNull() || info.EmailAddress.IsNull()) { return; } txtEmailAddress.Text = info.EmailAddress.ToString(); txtNickName.Text = info.NickName.ToString(); txtex0.Text = info.ex0; txtex1.Text = info.ex1; txtex2.Text = info.ex2; txtex3.Text = info.ex3; txtex4.Text = info.ex4; txtex5.Text = info.ex5; txtex6.Text = info.ex6; txtex7.Text = info.ex7; txtex8.Text = info.ex8; txtError.Text = info.LastSendError; //checkBoxStatus.Checked = info.LastSendStatus == 0 ? true : false; txtEmailAddress.Enabled = false; }
private void BindData() { long totals = 0; listView1.View = View.Details; listView1.Columns.Clear(); listView1.Items.Clear(); listView1.BeginUpdate(); Where where = null; ThreadPool.QueueUserWorkItem(new WaitCallback((o) => { 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); }), null); }
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(); }
private int SendEmails(int sends = 0) { int sendIndex = 0; //当前发送的邮件索引 int ips = 0; //记录发送多少邮件后更换IP int smtps = 0; int smtps2 = 0; int smtpIndex = 0; //记录发送多少邮件后更换SMTP、smtp发送失败次数、当前使用的smtp索引 EmailListHelper.ClearCacheAll(); Where where = new Where().And("LastSendStatus", 0, Operator.Equal); emailList = EmailListHelper.SelectListByAll(null, where).Where(e => e.LastSendError.IndexOf("Mailbox not found") == -1).ToList(); if (emailList.Count == 0) { return(0); //0正常发送结束 } //循环发送所有email foreach (EmailList e in emailList) { sendIndex++; if (exit) { clear(); WriteLog("已停止发送邮件!"); thread.Abort(); return(-1); } //-1停止发送邮件 string name = smtpInfo.UserName; if (name.IndexOf("@") != -1) { name = name.Split('@')[0]; //显示发件人 } int index = smtpInfo.SmtpServer.IndexOf("."); string smtpDomail = smtpInfo.SmtpServer.Substring(index + 1); string emailAddress = name + "@" + smtpDomail; //显示发件人EMAIL if (!template.ShowName.IsNullEmpty()) { name = template.ShowName; //显示模版里设置的发件人 } bool success = false; string msg = string.Empty; if (emailAddress.Trim().ToLower() == e.EmailAddress.Trim().ToLower()) { success = true; //不允许自己发给自己 } if (!success) { success = email.ClearTo() .From(name, emailAddress) .Subject(processText(template.Subject, e)) .Body(processText(template.Body, e)) .To(t => t.Add(e.NickName.IfNullOrEmpty(e.EmailAddress.Split('@')[0]), e.EmailAddress)) .Send(); msg = processError(email.ErrorMessage); if (sendSetting.SendInterval > 0) { Thread.Sleep(sendSetting.SendInterval.Value); //暂停时间 } } WriteLog("<" + e.NickName + ">" + e.EmailAddress + (success ? " 发送成功!" : " 发送出错:" + msg)); //最后一次发送情况 EmailList emailInfo = new EmailList(); emailInfo.EmailAddress = e.EmailAddress; emailInfo.LastSendStatus = success ? 1 : (sendSetting.SendRetryCount == e.SendCount + 1 ? 2 : 0); emailInfo.LastSendTime = DateTime.Now; emailInfo.LastSendSmtp = smtpInfo.SmtpServer + "|" + smtpInfo.UserName; emailInfo.LastSendError = msg; emailInfo.SendCount = e.SendCount + 1; EmailListHelper.Update(emailInfo); ips++; if (sendSetting.IPInterval > 0 && ips >= sendSetting.IPInterval) //换IP { ips = 0; WriteLog("正在更换IP....."); string ip = NetHelper.ChangeIP(sendSetting.ConnectType.Value, uiMsg, uiDone); if (ip.IsNullEmpty()) { WriteLog(sendSetting.MaxRetryCount + "次更换IP失败!"); return(1); } //1更换IP失败结束 WriteLog("更换IP:" + ip); } smtps++; if (!success) { smtps2++; } if (sendSetting.SmtpInterval > 0 && smtps >= sendSetting.SmtpInterval && smtpList.Count > 1) //换SMTP { UpdateSmtpListSendCount(smtpIndex, sendSetting.SmtpInterval.Value, smtps2); //更新smtp发送次数 smtps = 0; smtps2 = 0; smtpIndex++; if (smtpIndex + 1 > smtpList.Count) { smtpIndex = 0; //如果所有smtp发送完,将重新循环更换 } smtpInfo = smtpList[smtpIndex]; //更换下一个smtp WriteLog("更换SMTP:" + smtpInfo.SmtpServer + "|" + smtpInfo.UserName); email.Host(smtpInfo.SmtpServer) .Ssl(smtpInfo.SSL.Value) .Port(smtpInfo.SmtpPort.Value) .Credentials(smtpInfo.UserName, smtpInfo.SPassword); } } ; if (smtps > 0) { UpdateSmtpListSendCount(smtpIndex, smtps, smtps2); //更新smtp发送次数 } WriteLog("第" + (sends + 1) + "轮发送完成!"); return(SendEmails(sends + 1)); }
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); }