private string subject = string.Empty, mailto = string.Empty, body = string.Empty;
private int sucNum = 0;
private int TotalDate=0;
private string ConnString
string pathFull = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
string path = pathFull.Substring(0, pathFull.LastIndexOf(@"\"));
return @"Provider=Microsoft.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; //默认为秒
private int Interval
int timer = 0;
int totalMis = (TotalDate * UnitConversion * 1000);
timer = totalMis / (mailTotalCount-SentCount);
return timer;
private void Form1_Load(object sender, EventArgs e)
Control.CheckForIllegalCrossThreadCalls = false;
private void btnSendMail_Click(object sender, EventArgs e)
this.progressBar1.Visible = true;
this.lblProgress.Visible = true;
private bool Send(string mailTo, string subject, string body)
if (!IsEmail(mailTo)) //邮箱格式验证
WriteToTxt(DateTime.Now + " Faild " + mailTo, txtLogPath + " Error Message:邮箱格式不正确");
return false;
MailMessage msg = new MailMessage();
msg.From = new MailAddress("***@****", "xiaoyaosr", Encoding.UTF8);
if (mailTo.IndexOf(",") > -1)
ArrayList annexList = ReadTxt(txtAnnexPath);
for (int i = 0; i < annexList.Count; i++)
SmtpClient smtp = new SmtpClient("mail.163.com");
catch (Exception ex)
WriteToTxt(DateTime.Now + " Faild Error Message:" + ex.Message, txtLogPath);
this.notifyIcon1.ShowBalloonTip(Interval, "", ex.Message, ToolTipIcon.None);
return mailSent;
MailSend mailSend = new MailSend();
mailSend.iTotalCount = mailTotalCount;
void mailSend_onMailSendProgress(int total, int current)
if (this.InvokeRequired)
this.Invoke(new MailSend.dMailSendProgress(mailSend_onMailSendProgress), new object[] { total, current });
string percent = (((current + 1) *100) / mailTotalCount).ToString() + "%";
string progress = percent + " " + (current + 1) + "/" + mailTotalCount;
this.lableTimer.Text = progress;
转载于:https://blog.51cto.com/tang1qian2qian3/478500