朋友工作中需要将邮件群发给别人,但是每封信的抬头要修改接受人的称呼。一封一封的发肯定不现实,量大,而且易出错。
1,导出邮箱联系人到本地
姓名,First Name,电子邮件,E-mail Address,手机,Home Phone,固定电话,别名,生日,备用邮箱,家庭地址,公司名称,备注
导出后的格式如上所示。
2,构造正则表达式,提取姓名与邮箱
([\u4E00-\u9FA5]{2,3}),([-a-zA-Z0-9_][email protected][-a-zA-Z0-9]+\.com)
前面提取的是姓名(match.Groups[1].Value),后边是邮箱(match.Groups[2].Value)
3,我是将他们的对应关系 存入了Hashtable,然后问题就解决了。
1 Thread t = new Thread(new ThreadStart(() => 2 { 3 while (count < num) 4 { 5 MailMessage mail = new MailMessage(); 6 mail.From = new MailAddress(txtUsername.Text + "@qq.com", txtSendname .Text ); 7 mail.To.Add(new MailAddress(h[nm[count]].ToString(),nm[count ])); 8 mail.Subject = txtSubject.Text; 9 StringBuilder sb = new StringBuilder(1024 * 8); 10 string tmp = texContent.Text.Replace(txtOld.Text, txtOld.Text + nm[count]); 11 sb.Append(tmp); 12 mail.Body = sb.ToString(); 13 mail.IsBodyHtml = true; 14 SmtpClient sc = new SmtpClient("smtp.qq.com"); 15 sc.Credentials = new NetworkCredential(txtUsername.Text.Trim(), txtPassword.Text.Trim()); 16 try 17 { 18 sc.Send(mail); 19 txtLog.Invoke(new Action(() => 20 { 21 txtLog.AppendText(nm[count] + "√\r\n"); 22 })); 23 } 24 catch 25 { 26 txtLog.Invoke(new Action(() => 27 { 28 txtLog.AppendText(nm[count] + " " + h[nm[count]].ToString() + "is not available×××××××××\r\n"); 29 })); 30 } 31 count++; 32 } 33 if (count >= num) 34 { 35 MessageBox.Show("Send over!"); 36 btnSend.Invoke(new Action(() => 37 { 38 btnSend.Enabled = false; 39 })); 40 } 41 42 })); 43 t.Start();
时间: 2024-11-10 07:46:35