-
最新文章
-
目录
-
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;
this.progressBar1.Maximum = total;
this.progressBar1.Value = current;
if (total > 0 && subject.Length > 0)
{
UpdateMailState(mailto, 1);
if (current == total - 1)
this.notifyIcon1.ShowBalloonTip(Interval, "", "发送完毕,成功发送" + sucNum + "封", ToolTipIcon.None);
this.lableTimer.Text = "";
this.notifyIcon1.ShowBalloonTip(Interval, "", ex.Message, ToolTipIcon.None);
private void InitMailList(){}
private void LoadMailList(){ }
private void SentMailCount(){}
private void MarkErrorMail(string mail) {}
private void UpdateMailState(string mail, int state) {}
private void InitTime()
if (mailTotalCount > 0 && SentCount < mailTotalCount)
this.txtDateCount.Text = ((mailTotalCount - SentCount) * 10).ToString();
this.lblTime.Text = TimeConvert((mailTotalCount - SentCount) * 10);
private void btnAnnexSelect_Click(object sender, EventArgs e)
OpenFileDialog ofd = new OpenFileDialog();
string strFileName = "";
if (ofd.ShowDialog() == DialogResult.OK)
this.txtAnnex.Text = strFileName;
WriteToTxt(strFileName, txtAnnexPath);
ArrayList list = ReadTxt(txtAnnexPath);
if (list.Count > 0)
string str = string.Empty;
for (int i = 0; i < list.Count; i++)
string file = list[i].ToString();
this.lblAnnexList.Text = str.Trim(";".ToCharArray());
private void KillThread()
foreach (System.Diagnostics.Process thisproc in System.Diagnostics.Process.GetProcesses())
if (thisproc.ProcessName.Equals("MailGroupSends"))
private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
this.ShowInTaskbar = true;
this.WindowState = FormWindowState.Normal;
private void Form1_SizeChanged(object sender, EventArgs e)
if (this.WindowState == FormWindowState.Minimized)
this.ShowInTaskbar = false;
private void InitMailCategory()
OleDbConnection Conn = new OleDbConnection(ConnString);
string sql = @"select categoryid,categoryname from mailCategory where recordstate=0";
if (Conn.State == ConnectionState.Closed) Conn.Open();
OleDbCommand cmd = new OleDbCommand(sql, Conn);
OleDbDataReader reader = cmd.ExecuteReader();
DataTable table = new DataTable();
DataRow row = table.NewRow();
while (reader.Read())
row[0] = reader[0].ToString();
row[1] = reader[1].ToString();
if (reader != null) reader.Dispose();
this.comboBox_mailcategory.ValueMember = "categoryid";
this.comboBox_mailcategory.DisplayMember = "categoryname";
this.comboBox_mailcategory.DataSource = table;
this.comboBox_mailcategory.SelectedIndex = 0;
if (Conn.State == ConnectionState.Open) Conn.Close();
if (Conn != null) Conn.Dispose();
private void comboBox_mailcategory_SelectedIndexChanged(object sender, EventArgs e)
private string TimeConvert(int time)
int h = time / 3600;
int m = (time - h * 3600) / 60;
int s = time - h * 3600 - m * 60;
return h + "时" + m + "分" + s + "秒";
private bool IsEmail(string email)
string strExp = @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*";
Regex r = new Regex(strExp);
Match m = r.Match(email);
return m.Success ? true : false;
public delegate void dMailSendProgress(int total, int current);
public event dMailSendProgress onMailSendProgress;
for (int i = iSentCount; i < iTotalCount; i++)
if (onMailSendProgress != null)
onMailSendProgress(iTotalCount, i);
4
收藏
Ctrl+Enter 发布
发布
取消