The front desk does not have to write, the backstage execution method is possible.
1 namespaceSendMail2 {3 Public Partial classSendMail_Page:System.Web.UI.Page4 {5 protected voidPage_Load (Objectsender, EventArgs e)6 {7 if(!IsPostBack)8 {9 Thstart ();Ten } One } A Publicthread[] Threads =Newthread[5]; - //Open Thread - Public voidThstart () the { -ThreadStart THSRT =NewThreadStart (SendMail); - //Looping 5 Threads - for(inti =0; I <5; i++) + { -Threads[i] =NewThread (THSRT); +Threads[i]. IsBackground =true; A } at //Loop through all 5 threads - foreach(Thread thinchthreads) - { - th. Start (); - } - } in - Public voidSendMail () to { + Try - { theSystem.Net.Mail.SmtpClient client =NewSystem.Net.Mail.SmtpClient (); *Client. Host ="smtp.qq.com"//qq mail box with this, the Internet is easy to use smtp.126.com, to see the situation is determined $Client. useDefaultCredentials =false;Panax NotoginsengClient. Deliverymethod =System.Net.Mail.SmtpDeliveryMethod.Network; -Client. Credentials =NewSystem.Net.NetworkCredential ("Send the Email box","Email Password");//Verify that the email box and this one are not theSystem.Net.Mail.MailMessage Message =NewSystem.Net.Mail.MailMessage (); +Message.from =NewSystem.Net.Mail.MailAddress ("Send the Email box"); AMESSAGE.TO.ADD ("Receive your email box"); the +Message.subject ="User Tests"; -Message.body ="topic-Test-Email delivery"; $Message.subjectencoding =System.Text.Encoding.UTF8; $Message.bodyencoding =System.Text.Encoding.UTF8; -Message.priority =System.Net.Mail.MailPriority.High; -message.isbodyhtml =true; the client. Send (Message); -Thread.Sleep ( +);Wuyi } the Catch(Exception) - { Wu //Loop through all 5 threads - foreach(Thread thinchthreads) About { $ //Abort Thread - th. Abort (); - } - } A } + } the}
Send mailboxes in multiple threads (send n messages to one user at a time)