<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading;
    using System.Web.Mail;

    namespace ConsoleApplication1
    {
      
    public delegate void CallBack(bool state, int count);
        
    public class Program
        {
           
            
    public void Show(bool state,int count)
            {
                Console.WriteLine(
    "{0}-{1}",state,count);  
            }
            
    static void Main(string[] args)
            {
                
    int tempCount = 120;
                
    int tempWhileCount = (tempCount / 100* 100;
                
    int tempOtherCount = tempCount - tempWhileCount;

                Console.WriteLine(tempWhileCount);
                Console.WriteLine(tempOtherCount);

                
    //指定線程數(shù)
                int size = 10;
                size 
    = tempWhileCount==0?(0):(tempWhileCount <= 100 ? (10) : (tempWhileCount <= 1000 ? (20) : (25)));
             
                List
    <MailInfo> lall = new List<MailInfo>();
                
    //添加郵件信息
                for (int i = 0; i <tempCount; i++)
                {
                    lall.Add(
    new MailInfo("三毛"+ i.ToString(),"wangdetian16" + i.ToString() + "@qq.com"));
                }
                
    //創(chuàng)建多線程
                for (int i = 0; i < size; i++)
                {
                    ThreadData temptd 
    = new ThreadData(new CallBack(new Program().Show));
                    List
    <MailInfo> tempLi = new List<MailInfo>();
                    
    for (int j = i * (tempWhileCount / size); j < (i * (tempWhileCount / size) + tempWhileCount / size); j++)
                    {
                        tempLi.Add(lall[j]);
                    }
                    temptd.LisMails 
    = tempLi;
                    Thread tempThread 
    = new Thread(new ThreadStart(temptd.Run));
                    tempThread.Start();


                }
                ThreadData temptdOther 
    = new ThreadData(new CallBack(new Program().Show));
                List
    <MailInfo> tempLiOther = new List<MailInfo>();
                
    for (int j = tempWhileCount; j < tempCount; j++)
                {
                    tempLiOther.Add(lall[j]);
                }
                temptdOther.LisMails 
    = tempLiOther;
                Thread tempThreadOther 
    = new Thread(new ThreadStart(temptdOther.Run));
                tempThreadOther.Start();
                



                
    //ThreadData thdata1 = new ThreadData();
                
    //List<string> l1 = new List<string>();
                
    //for (int i = 0; i < 1000; i++)
                
    //{
                
    //    l1.Add("wangdetian16"+i.ToString()+"@163.com");
                
    //}
                
                
    //thdata1.LisMails = l1;
                
    //Thread thread = new Thread(new ThreadStart(thdata1.Run));
                
    //thread.Start();

                
    //ThreadData thdata2 = new ThreadData();
                
    //List<string> l2 = new List<string>();
                
    //for (int i = 0; i < 10; i++)
                
    //{
                
    //    l2.Add("wangdetian18" + i.ToString() + "@163.com");
                
    //}
                
    //thdata2.LisMails = l2;
                
    //Thread thread1 = new Thread(new ThreadStart(thdata2.Run));
                
    //thread1.Start();
                
       
            }
        }

        
    public class ThreadData
        {
         
            
    public static string MailMessage = "{0}你好你人物要做近三分薩拉夫接撒立法精神多了幾分當(dāng)上了副駕駛的發(fā)生大風(fēng)藍(lán)色隊服那里公司發(fā)展規(guī)劃的";
            
    private List<MailInfo> _LisMails;
            
    public static string frommail = "wangdetian116688@163.com";//System.Configuration.ConfigurationManager.AppSettings["frommail"];
            public static string username = "wangdetian116688";//System.Configuration.ConfigurationManager.AppSettings["username"];
            public static string password = "987654321";//System.Configuration.ConfigurationManager.AppSettings["password"];
            public List<MailInfo> LisMails
            {
                
    set { this._LisMails = value; }
                
    get { return this._LisMails; }
            }
            
    public CallBack CB;
            
    public ThreadData(CallBack cb)
            {
                
    this.CB = cb;
            }
            
    public void Run()
            {
                
    int i = 0;

                
    foreach (MailInfo s in LisMails)
                {
                    System.Threading.Thread.Sleep(
    1000);
                    Console.WriteLine(
    string.Format(MailMessage,s.MailName+s.MailAddress));
                    CB(
    false,++i);
                  
    //  SendMail20(s.MailAddress, s.MailName, string.Format(MailMessage, s.MailName));
                }
                CB(
    true, i);
            }
            
    private bool SendMail(string toMail, string subject, string body)
            {
                
    try
                {


                    
    string fromMail = ThreadData.frommail;
                    MailMessage myMail 
    = new MailMessage();
                    myMail.From 
    = fromMail;
                    myMail.To 
    = toMail;
                    
    //myMail.Cc = ccMail;
                    
    //myMail.Bcc = bccMail;
                    myMail.Subject = subject;
                    myMail.Body 
    = body;
                    myMail.BodyFormat 
    = MailFormat.Html;

                    
    //附件
                    string ServerFileName = "";
                    
    //if (this.upfile.PostedFile.ContentLength != 0)
                    
    //{
                    
    //    string upFileName = this.upfile.PostedFile.FileName;
                    
    //    string[] strTemp = upFileName.Split('.');
                    
    //    string upFileExp = strTemp[strTemp.Length - 1].ToString();
                    
    //    ServerFileName = Server.MapPath(DateTime.Now.ToString("yyyyMMddhhmmss") + "." + upFileExp);
                    
    //    this.upfile.PostedFile.SaveAs(ServerFileName);
                    
    //    myMail.Attachments.Add(new MailAttachment(ServerFileName));
                    
    //}


                    myMail.Fields.Add(
    "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"1);
                    myMail.Fields.Add(
    "http://schemas.microsoft.com/cdo/configuration/sendusername", ThreadData.username); //發(fā)送方郵件帳戶
                    myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", ThreadData.password); //發(fā)送方郵件密碼

                    SmtpMail.SmtpServer 
    = "smtp." + fromMail.Substring(fromMail.IndexOf("@"+ 1);
                    SmtpMail.Send(myMail);

                    
    return true;
                }
                
    catch
                {
                    
    return false;
                }
            }
            
    private bool SendMail20(string toMail, string subject, string body)
            {
                
    try
                {

                    System.Net.Mail.MailAddress from 
    = new System.Net.Mail.MailAddress(ThreadData.frommail); //郵件的發(fā)件人
                    
    //string fromMail = ThreadData.frommail;
                    System.Net.Mail.MailMessage myMail = new System.Net.Mail.MailMessage();
                    
    //設(shè)置郵件的標(biāo)題
                    myMail.Subject = subject;
                    
    //設(shè)置郵件的發(fā)件人
                    
    //Pass:如果不想顯示自己的郵箱地址,這里可以填符合mail格式的任意名稱,真正發(fā)mail的用戶不在這里設(shè)定,這個僅僅只做顯示用
                    myMail.From = from;
                    
    //MailAddress(address, displayName)
                    myMail.To.Add(new System.Net.Mail.MailAddress(toMail));
                   
                    
    ////設(shè)置郵件的抄送收件人
                    
    ////這個就簡單多了,如果不想快點(diǎn)下崗重要文件還是CC一份給領(lǐng)導(dǎo)比較好
                    //mail.CC.Add(new MailAddress("Manage@hotmail.com", "尊敬的領(lǐng)導(dǎo)");

                    
    //設(shè)置郵件的內(nèi)容
                    myMail.Body = body;
                    
    //設(shè)置郵件的格式
                    myMail.BodyEncoding = System.Text.Encoding.GetEncoding("gb2312");
                    myMail.IsBodyHtml 
    = true;
                    
    //設(shè)置郵件的發(fā)送級別
                    myMail.Priority = System.Net.Mail.MailPriority.Normal;

                    
    //設(shè)置郵件的附件,將在客戶端選擇的附件先上傳到服務(wù)器保存一個,然后加入到mail中
                    
    //string fileName = txtUpFile.PostedFile.FileName.Trim();
                    
    //fileName = "D:\UpFile\" + fileName.Substring(fileName.LastIndexOf("\") + 1);
                    
    //txtUpFile.PostedFile.SaveAs(fileName); // 將文件保存至服務(wù)器
                    
    //mail.Attachments.Add(new Attachment(fileName));

                    myMail.DeliveryNotificationOptions 
    = System.Net.Mail.DeliveryNotificationOptions.OnSuccess;

                    System.Net.Mail.SmtpClient client 
    = new System.Net.Mail.SmtpClient();
                    
    //設(shè)置用于 SMTP 事務(wù)的主機(jī)的名稱,填I(lǐng)P地址也可以了
                    client.Host = "smtp." + ThreadData.frommail.Substring(ThreadData.frommail.IndexOf("@"+ 1); 
                    
    //"smtp.hotmail.com";// "smtp." + fromMail.Substring(fromMail.IndexOf("@") + 1);
                    
    //設(shè)置用于 SMTP 事務(wù)的端口,默認(rèn)的是 25
                    
    //client.Port = 25;
                    client.UseDefaultCredentials = false;
                    
    //這里才是真正的郵箱登陸名和密碼,比如我的郵箱地址是 wangdetian@126.com, 我的用戶名為 hbgx ,我的密碼是 xgbh
                    client.Credentials = new System.Net.NetworkCredential(ThreadData.username, ThreadData.password);
                    client.DeliveryMethod 
    = System.Net.Mail.SmtpDeliveryMethod.Network;
                    
    //都定義完了,正式發(fā)送了,很是簡單吧!
                    client.Send(myMail);    

                    
    return true;
                }
                
    catch
                {
                    
    return false;
                }
            }
           
        }
        
    public class MailInfo
        {
            
    public string MailName;
            
    public string MailAddress;
            
    public string MailMessage;
            
    public MailInfo(string mailName, string mailAddress)
            {
                
    this.MailName = mailName;
                
    this.MailAddress = mailAddress;
            }
            
    public MailInfo(string mailName, string mailAddress, string mailMessage)
            {
                
    this.MailName = mailName;
                
    this.MailAddress = mailAddress;
                
    this.MailMessage = mailMessage;
            }
        } 
           
        }


     

    posted on 2010-07-29 09:49 sanmao 閱讀(331) 評論(0)  編輯  收藏

    只有注冊用戶登錄后才能發(fā)表評論。


    網(wǎng)站導(dǎo)航:
     

    常用鏈接

    留言簿(5)

    隨筆分類

    隨筆檔案

    搜索

    •  

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 91亚洲国产成人精品下载| 我想看一级毛片免费的| 亚洲三级电影网站| 热99re久久免费视精品频软件| 男人和女人高潮免费网站| 亚洲综合激情九月婷婷| 国产免费久久精品| 在线观看AV片永久免费| 男女一边桶一边摸一边脱视频免费| 亚洲二区在线视频| 国产V亚洲V天堂A无码| 亚洲国模精品一区| 全免费一级毛片在线播放| 日韩精品免费一级视频| 久久免费国产精品一区二区| 一个人看的免费视频www在线高清动漫 | 亚洲免费在线播放| jizz18免费视频| 免费看黄福利app导航看一下黄色录像| 亚洲视频在线不卡| 亚洲an日韩专区在线| 亚洲一区中文字幕在线观看| 91亚洲精品第一综合不卡播放| 亚洲AV无码国产精品麻豆天美 | 亚洲AV成人精品一区二区三区| 亚洲精品亚洲人成在线观看麻豆 | 大地资源中文在线观看免费版| 一级毛片免费不卡| 国产va在线观看免费| 免费看又黄又无码的网站| 19禁啪啪无遮挡免费网站| 99热这里有免费国产精品| 野花高清在线观看免费完整版中文| 最近在线2018视频免费观看| 欧美a级在线现免费观看| 日本一道综合久久aⅴ免费| 国产亚洲精品影视在线产品| 久久丫精品国产亚洲av不卡| 亚洲永久网址在线观看| 一个人看的www免费高清| 99爱在线观看免费完整版|