作者c邮件群发系统代码解析

邮件群发系统  时间:2021-01-31  阅读:()

概要

子线程工作发送成功邮件做标记逐条提取数据气泡提示信息最小化到托盘实时进度条

代码us ing System;us ing System.Collections;us ing System.Collections.Generic;using System.ComponentModel;using System.Data;us ing System.Data.OleDb;us ing System.Threading;using System.Text;using System.Windows.Forms;us ing System.Net.Mail;us ing System.Net;us ing System.Text.RegularExpress ions;names pace M ailGroup Sends

{public partial class Form1 :Form

{public Form1()

{

Initialize Comp onent();

}private string subject=string.Empty;private string mailto=string.Empty;private string body=string.Empty;private int sucNum=0;private int TotalDate

{get

{if(this.txtDateCount.Text.Trim().Length>0)return Convert.ToInt32(this.txtDateCount.Text.Trim());return 4;

}set { this.txtDateCount.Text=value.ToString(); }

}private string ConnString

作者逍遥散人 Blog:http://xiaoyaosrblog 51cto com

{get

{string pathFull=

Sys tem.Diagn ostics.Pro ces s.GetCurrentPro ces s().M ainModu le.FileName;string path=pathFull.Substring(0,pathFull.LastIndexOf(@"\"));return@"Provider=Micros oft.Jet.OLEDB.4.0;Data Source="+path+@"\mail.mdb";

}

}private bool mailSent=false; //邮件是否发送成功private int mailTotalCount=0;private int CategoryId=0;private int SentCount=0; //已发送数private int UnitConversion=1; //默认为秒

///<summary>

///发送间隔

///</summary>private int Interval

{get

{int timer=0;int totalMis=(TotalDate*UnitConvers ion* 1000);timer=to talM is / (mailTo talCount-S entCount);return timer;

}

}

///<summary>

///提取邮件

///</summary>private void InitMailList()

{

O leDbConnection Conn=new OleDbConnection(ConnString);try

{string strWhere=CategoryId==1000? "" : "and categoryid="+CategoryId+"orderby isSend,uyx";string sqlStr=@"select top 1 uyxfrom[usermail]where isDelete=0 and IsSend=0"+strWhere;if(Conn.State==ConnectionState.Clos ed)Conn.Open();

OleDb Command cmd=new OleDb Command(s qlStr,Conn);

作者逍遥散人 Blog:http://xiaoyaosrblog 51cto com

OleDbDataReader reader=cmd.ExecuteReader();mailto=string.Empty;wh ile(re ad er.Re ad())

{mailto+=reader[0].To String()+",";

}reader.Clos e();if(reader!=null)reader.Dispos e();mailto=mailto.Trim(",".ToCharArray());

}catch(Exception ex)

{

Mess ageBox.Show(ex.Mess age,"错误",MessageBoxButtons.OK,MessageBoxIcon.Error);

}fin a lly

{if(Conn.State==Connection State.Open)Conn.Clo se();if(Conn!=null)Conn.Disp ose();

}

}

///<summary>

///加载邮件列表

///</summary>private void LoadMailList()

{this.dataGridView 1.Co lumn s.Clear();if(this.dataGridView 1.Rows.Count>0)this.dataGridView 1.Rows.Cle ar();dataGridView1.RowHeadersWidth=21;

DataGridViewTextBo xColumn column=new DataGridViewTextBo xColumn();column.ReadOnly=true;column.HeaderText="邮箱列表";column.DisplayIndex=0;column.Name="邮箱列表";column.Width=120;dataGrid View1.Columns.Add(column);column=new DataGridViewTextBo xColumn();column.ReadOnly=true;column.HeaderText="状态";column.DisplayIndex=1;

作者逍遥散人 Blog:http://xiaoyaosrblog 51cto com

dataGrid View1.Columns.Add(column);

O leDbConnection Conn=new OleDbConnection(ConnString);try

{string strWhere=CategoryId==1000?"" : "and categoryid="+CategoryId+"orderby isSend,uyx";string sql=@"select uyx,Is Send fromusermail where isDelete=0"+strWhere;if(Conn.State==ConnectionState.Clos ed)Conn.Open();

OleDbCommand cmd=new OleDbCommand(s ql,Conn);

OleDbDataReader reader=cmd.ExecuteReader();mai lTo talCo unt=0;wh ile(re ad er.Re ad())

{

DataGridViewRow dgvr=new DataGridViewRow();

DataGridViewTextBo xCell cell=new DataGridViewTextBo xCe ll();cell.Value=reader[0].To String();dgvr.Ce lls.A dd(c e ll);cell=new DataGridViewTextBo xCell();cell.Value="●";c ell.Style.ForeCo lor=Convert.To Int32(reader[1])==0?

Sys tem.Drawin g.Co lo r.Ye l lo w:Sy s t em.Drawin g.Co lo r.Gre en;dgvr.Ce lls.A dd(c e ll);dataGridView 1.Rows.Add(dgvr);ma ilT o t a lCo un t++;

}reader.Clos e();if(reader!=null)reader.Dispos e();this.lb lmai lCount.Text=" "+SentCount+"/"+mailTotalCount+" ";

}catch

{

}fin a lly

{if(Conn.State==Connection State.Open)Conn.Clo se();if(Conn!=null)Conn.Dispose();

}

}

///<summary>

作者逍遥散人 Blog:http://xiaoyaosrblog 51cto com

///已发送邮件个数

///</summary>private void SentMailCount()

{

O leDbConnection Conn=new OleDbConnection(ConnString);try

{string strWhere=CategoryId==1000? "" : "and categoryid="+CategoryId;string sqlStr=@"select uyxfrom[usermail]where isDelete=0 and IsSend=1 "+strWhere;if(Conn.State==ConnectionState.Clos ed)Conn.Open();

OleDbDataAdapter adapter=new OleDbDataAdapter(sqlStr,Conn);

DataSet ds=new DataSet();a d ap te r.F ill(d s);

SentCount=ds.Tab les[0].Ro ws.Count;

}catch(Exception ex)

{

Mess ageBox.Show(ex.Mess age,"错误",MessageBoxButtons.OK,

MessageBoxIcon.Error);

}fin a lly

{if(Conn.State==Connection State.Open)Conn.Clo se();if(Conn!=null)Conn.Dispose();

}

}

///<summary>

///标记出错的邮箱

///</summary>

///<p aram name="mail"></p aram>private void MarkErrorMail(string mail)

{

O leDbConnection Conn=new OleDbConnection(ConnString);try

{string sql="update usermail set IsDelete=10 where uyx='"+mail+"' ";if(Conn.State==ConnectionState.Clos ed)Conn.Open();

OleDb Command cmd=new OleDbCommand(s ql,Conn);cmd.ExecuteNonQuery();

}catch

{ }

作者逍遥散人 Blog:http://xiaoyaosrblog 51cto com

{if(Conn.State==Connection State.Open)Conn.Clo se();if(Conn!=null)Conn.Disp ose();

}

}

///<summary>

///修改已发送邮件状态

///</summary>

///<p aram name="mail"></p aram>private void UpdateMailState(string mail, int state)

{

O leDbConnection Conn=new OleDbConnection(ConnString);try

{string where=string.Empty;if(ma il.Length>0)

{

WriteToTxt(DateTime.Now+" Success "+mail, txtLogPath);if(ma il.In d e xO f(",")>-1)'")+"' ";where="and uyx='"+mail+"'";

}e ls e

{where="and IsSend=1";

}string category=CategoryId==1000? "" : "and categoryid="+CategoryId;string sql="update usermail set Is Send="+state+"where IsDelete=0"+category+wh e re;if(Conn.State==ConnectionState.Clos ed)Conn.Open();

OleDb Command cmd=new OleDbCommand(s ql,Conn);cmd.ExecuteNonQuery();

}catch

{ }fin a lly

{if(Conn.State==Connection State.Open)Conn.Clo se();if(Conn!=null)Conn.Disp ose();

}

作者逍遥散人 Blog:http://xiaoyaosrblog 51cto com

}

///<summary>

///邮件发送

///</summary>

///<p aram n ame="mailTo"></p aram>

///<p aram name="subject"></p aram>

///<p aram name="body"></param>

///<re tu rns></re tu rns>private bool Send(string mailTo, string subject,string body)

{try

{if(!Is Ema il(mailTo))

{

WriteToTxt(DateTime.Now+" Faild "+mailTo, txtLogPath+"Error Message:邮箱格式不正确");

M arkErro rM ail(mai lT o);return fals e;

}if(ma ilTo.Substring(mailTo.Length- 1)=="." | |mai lTo.Substring(mailTo.Length- 1)==",")

{

WriteToTxt(DateTime.Now+" Faild "+mailTo, txtLogPath+"Error Message:邮箱格式不正确");

M arkErro rM ail(mai lT o);return fals e;

}

MailMessage msg=new MailMessage();ms g.From=new MailAddress("***@****","xiaoyaos r",Enco ding.UTF8);if(ma ilT o.In d e xO f(",")>-1)ms g.Bc c.Add(mailTo);e ls ems g.To.A dd(mailTo);msg.Subject=subject;ms g.Body=body;

ArrayList annexList=ReadTxt(txtAnnexPath);for(int i=0; i<annexList.Count; i++)

{msg.Attachments.Add(new Attachment(annexList[i].ToString()));

}

S mtpClient s mtp=new SmtpClient("mail.163.com");

作者逍遥散人 Blog:http://xiaoyaosrblog 51cto com

s mtp.Credentials=new NetworkCredential("***@****", "*******");smtp.Send(msg);mailSent=true;sucNum++;

}catch(Exception ex)

{if(ex.Mess age.IndexOf("http://www.ipmotor.com/smtp_err.htm")>-1)

{

WriteToTxt(DateTime.Now+" Faild Error Message:"+ex.Message,txtLogPath);this.notifyIcon 1.ShowBallo onTip(Interval, "",ex.Me ssage,Too lTip Icon.None);

System.Threading.Thread.Sleep(Interval*2);base.Dispose(true);

App lication.ExitThread();

Ki llTh re a d();

}

WriteToTxt(DateTime.Now+" Faild "+mailTo+" Error Message:"+ex.Message, txtLogPath);

M ark Erro rM a il(ma ilT o);mailSent=false;

}return mailSent;

}

//*******************************************************************//

//开始发送public void StartMailSend()

{

MailSend mailSend=new MailSend();ma i lS e n d.iT ot a lCount=ma ilT o t a lCo unt;ma i lS e n d.int e rva l=In t e rva l;mailSend.iSentCount=SentCount;mai lSend.onM ailSendProgres s+=new

M ailS end.dM ailS endProgres s(mailS en d_o nM ailS endProgres s);mailSend.Start();

}

//同步更新void mailSend_onMailSendProgress(int total, int current)

{try

作者逍遥散人 Blog:http://xiaoyaosrblog 51cto com

bgpto:独立服务器夏季促销,日本机器6.5折、新加坡7.5折,20M带宽,低至$93/月

bgp.to对日本机房、新加坡机房的独立服务器在搞特价促销,日本独立服务器低至6.5折优惠,新加坡独立服务器低至7.5折优惠,所有优惠都是循环的,终身不涨价。服务器不限制流量,支持升级带宽,免费支持Linux和Windows server中文版(还包括Windows 10). 特色:自动部署,无需人工干预,用户可以在后台自己重装系统、重启、关机等操作!官方网站:https://www.bgp.to...

IonSwitch:$1.75/月KVM-1GB/10G SSD/1TB/爱达荷州

IonSwitch是一家2016年成立的国外VPS主机商,部落上一次分享的信息还停留在2019年,主机商提供基于KVM架构的VPS产品,数据中心之前在美国西雅图,目前是美国爱达荷州科德阿伦(美国西北部,西接华盛顿州和俄勒冈州),为新建的自营数据中心。商家针对新数据中心运行及4号独立日提供了一个5折优惠码,优惠后最低1GB内存套餐每月仅1.75美元起。下面列出部分套餐配置信息。CPU:1core内存...

Gcorelabs:美国GPU服务器,8路RTX2080Ti;2*Silver-4214/256G内存/1T SSD,1815欧/月

gcorelabs怎么样?gcorelabs是创建于2011年的俄罗斯一家IDC服务商,Gcorelabs提供优质的托管服务和VPS主机服务,Gcorelabs有一支强大的技术队伍,对主机的性能和稳定性要求非常高。Gcorelabs在 2017年收购了SkyparkCDN并提供全球CDN服务,目标是进入全球前五的网络服务商。G-Core Labs总部位于卢森堡,在莫斯科,明斯克和彼尔姆设有办事处。...

邮件群发系统为你推荐
美国10次啦导航gps卫星导航用的卫星应该是美国的吧?那有限几十颗卫星怎么能同时给地面上如此多的终端提供导航呢?集成显卡和独立显卡哪个好独立显卡和集成显卡哪个更好些莫代尔和纯棉哪个好纯棉含莫代尔和100%莫代尔哪个好迈腾和帕萨特哪个好帕萨特和迈腾哪个车好?机械表和石英表哪个好机械表好还是石英表好,看专家如何分析石英表和机械表哪个好手表是电子手表好还是机械手表好?等额本息等额本金哪个好房贷是等额本金划算还是等额本息划算手机音乐播放器哪个好手机音乐播放器音质好的APP是那款核芯显卡与独立显卡哪个好独立显卡和核芯显卡有什么区别网校哪个好请问在网校排名中,哪个网校是最好的?想找一家最好的来选择啊?
二级域名查询 过期域名查询 网通vps 独享100m Dedicated isatap 美国主机论坛 免备案空间 网站监控 qq数据库 怎样建立邮箱 softbank邮箱 isp服务商 电信虚拟主机 hdd 论坛主机 电信网络测速器 卡巴斯基官网下载 黑科云 闪讯网 更多