private void button3_Click(object sender, EventArgs e)
        {
            for (int iSender = 0; iSender < 25; iSender++)
            {
                ThreadSender[iSender] = new Thread(new ThreadStart(MailSender));
                ThreadSender[iSender].IsBackground = true;
                ThreadSender[iSender].Start();
            }
            button3.Visible =false;
            rester.Visible = true;
            button3.Enabled = false;
            timer2.Enabled = true;
        }        public static Object SynchronizeVariable = "locking variable";
        public static int iSynchronize = 0;
        private void MailSender()
        {
            lock (SynchronizeVariable)
                for (int iRow = iSynchronize; iRow < table.Rows.Count; iRow++)
                {
                    if (iSynchronize < table.Rows.Count)
                    {
                        strTo = table.Rows[iSynchronize]["mail"].ToString();
                     
                        strSubject = table.Rows[iSynchronize]["mail"].ToString();
                        Interlocked.Increment(ref iSynchronize);
                    }
                    else
                    {
                        Thread.CurrentThread.Abort();
                    }
                    try
                    {                        mail.to = strTo;
                        mail.toname = "您好";
                        mail.from = sendmail;
                        mail.fromname = sendnames;
                        mail.title = titles;
                        mail.body = contents ;
                        mail.useAttachment = false;
                        Email email = new Email();
                        email.Mail = mail;///直接用DNS发送邮件的一个类!不成功就用
                        if (!email.SendMail())   //SMTP服务器发送
                        {
                            MailMessage Message = new MailMessage(sendmail, strTo);
                            Message.IsBodyHtml = true;
                            Message.Subject = titles;
                            Message.Body = contents;                            SmtpClient smtpClient = new SmtpClient(table1.Rows[numstime]["smtp"].ToString());
                            smtpClient.Credentials = new NetworkCredential(table1.Rows[m]["smtpname"].ToString(), table1.Rows[m]["smtppass"].ToString());
                            smtpClient.Send(Message);
                            bState = true;
                            this.strMessage = strSubject;
                            this.listView1.Invoke(new EventHandler(ListSended));
                          
                        }
                        else
                        {
                            bState = true;
                            this.strMessage = strSubject;
                            this.listView1.Invoke(new EventHandler(ListSended));        
                        }                    }
                    catch
                    {
                        bState = false;
                        this.strMessage = strSubject;
                        this.listView2.Invoke(new EventHandler(ListSended));
                    }                    Monitor.PulseAll(SynchronizeVariable);
                    if (iSynchronize < table.Rows.Count)
                    {
                        Monitor.Wait(SynchronizeVariable);
                    }
                    else
                    {
                        Thread.CurrentThread.Abort();
                    }
                }        }        public void ListSended(object sender, EventArgs e)
        {
            if (bState == true)
            {
                this.listView1.Items.Add(this.strMessage);
                //this.listView1.Update();
            }
            if (bState == false)
            {
                this.listView2.Items.Add(this.strMessage);
                //this.listView2.Update();
            }
        }这段是我发邮件的主要代码!
用多线程发送!
可是我发现发送的过程非常慢!
大概5秒左右一个显示成功或者失败在LISTVIEW里
可不知道是哪的问题啊!
请高手指点啊!
解决了100分送!
分不够还可以加!!
只要问题能解决就可以!

解决方案 »

  1.   

    为什么要多线程发送,一个BCC指定多个电子邮件,就全部发送了,并且收件人不知道是群发的。
      

  2.   

    同意楼上的smtp中已经定义了一个邮件发送给多个用户的方式了
      

  3.   

    别的做邮件群发的软件是如何做的啊!
    是用多线程还是BCC呀!
    想请教下!
      

  4.   

    to ldhao(翰海) 
    是因为你每次都要登陆的问题吧
    试一下吧登陆服务器写在前面
    每次只负责发送,不要登陆了写在什么前面???
    我发送前要找SMTP服务器还是要连的啊
      

  5.   

    to angel_bear(angelbear) 
    你说的登陆一次给多个用户发送邮件好象就是BCC的方法吧!
      

  6.   

    自己UP!
    想问问高手那些成熟的群发软件的发送过程是怎么来发送的!
    直接发送还是用SMTP服务器来发送!
    然后是用多线程还是用了BCC的方式!
    为什么我的速度就是比较慢啊