Send mailboxes in multiple threads (send n messages to one user at a time)

Source: Internet
Author: User
Tags mailmessage smtpclient

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.