1 delegate bool sendMsgDelegate(string server, string username, string password, string toaddr, string titel, string body); //申明委托
2 private static object obj = new object();
3 static int count = 0; //计数
4 static int sucessCount = 0; //成功的数量
5 static int total = 0; //
6 private static AutoResetEvent autoEvent = new AutoResetEvent(false);
7
8 public static bool sendMsg(string server, string username, string password, string toaddr, string titel, string body)
9 {
10 return EmailBuild.SendMail(server, username, password, toaddr, titel, body);
11 // return true;
12 }
13
14 public static void SendCallBack(IAsyncResult asynceresult)
15 {
16 sendMsgDelegate ss = (sendMsgDelegate)asynceresult.AsyncState;
17 lock (obj)
18 {
19 count++;
20 bool result = ss.EndInvoke(asynceresult);
21 if (result)
22 {
23 sucessCount++;
24 }
25 if (count == total)
26 {
27 autoEvent.Set();
28 }
29 }
30 }
31 /// <summary>
32 /// 邮件群发
33 /// </summary>
34 /// <param name="title">主题</param>
35 /// <param name="body">内容</param>
36 /// <param name="list">会员集合</param>
37 public static void Send(string title, string body, IList<Patti.Model.CustomersInfo> list)
38 {
39 int n = 0;
40 IList<Patti.Model.MailsettingInfo> EmList = (new Patti.BLL.MailsettingService()).GetListByDataTable("*", "", "MailID", 1, 1, "0", out n);
41 if (EmList.Count <= 0)
42 {
43 Loggor.Log("邮箱发送", "GetCountAndTime", "邮箱参数不对");
44 }
45 string server = EmList[0].MailSmtp;
46 string username = EmList[0].MailName;
47 string password = EmList[0].MailPwd;
48 total = list.Count;
49 DateTime t1 = DateTime.Now;
50 sendMsgDelegate ss = new sendMsgDelegate(sendMsg);
51
52 for (int i = 0; i < list.Count; i++)
53 {
54 if (list[i].CEmail != "")
55 {
56 IAsyncResult asyceresult = ss.BeginInvoke(server, username, password, list[i].CEmail, title, body, SendCallBack, ss);
57 }
58 }
59 autoEvent.WaitOne();
60 DateTime t2 = DateTime.Now;
61 //watch.Stop();
62 Loggor.Log("邮箱发送", "GetCountAndTime", "会员总数为:" + list.Count + ";成功发送" + sucessCount + "个邮箱;总花费的时间为:" + (t2 - t1));
63 }
首先把发送不成功的错误信息输出来看看到底什么问题。还有你的邮件服务器是否支持所哟说邮件,可能有的邮箱被限制了不能发送
如果全部的QQmail的邮件都发不出去,说明你的代理是有问题的
如果是一部分QQmail发不过去,那可能和他们的邮箱的设置是有关系的