Exemple #1
0
        /// <summary>
        /// workQueue_UserWork
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private static void workQueue_UserWork(object sender, WorkQueue <MailPara> .EnqueueEventArgs e)
        {
            MailPara mp = (MailPara)e.Item;

            setSend(mp.sendid, "送信中", mp.address);
            if (NCMail.SendEmail(mp.subject, mp.body, mp.htmlbody, mp.picfile, mp.address, mp.user, mp.password, mp.from, mp.to, mp.servertype))
            {
                setSend(mp.sendid, "送信完", mp.address);
            }
            else
            {
                setInvidMail(mp.to);
            }
            Thread.Sleep(15);
        }
Exemple #2
0
        /// <summary>
        /// 开始送信
        /// </summary>
        private static void startSend()
        {
            WorkQueue <MailPara> workQueue_Outlook = new WorkQueue <MailPara>(5);

            workQueue_Outlook.UserWork      += new UserWorkEventHandler <MailPara>(workQueue_UserWork);
            workQueue_Outlook.WorkSequential = true;

            WorkQueue <MailPara> workQueue_HotMail = new WorkQueue <MailPara>(5);

            workQueue_HotMail.UserWork      += new UserWorkEventHandler <MailPara>(workQueue_UserWork);
            workQueue_HotMail.WorkSequential = true;

            WorkQueue <MailPara> workQueue_GMail = new WorkQueue <MailPara>(5);

            workQueue_GMail.UserWork      += new UserWorkEventHandler <MailPara>(workQueue_UserWork);
            workQueue_GMail.WorkSequential = true;

            WorkQueue <MailPara> workQueue_YMail = new WorkQueue <MailPara>(5);

            workQueue_YMail.UserWork      += new UserWorkEventHandler <MailPara>(workQueue_UserWork);
            workQueue_YMail.WorkSequential = true;

            WorkQueue <MailPara> workQueue_AMail = new WorkQueue <MailPara>(5);

            workQueue_AMail.UserWork      += new UserWorkEventHandler <MailPara>(workQueue_UserWork);
            workQueue_AMail.WorkSequential = true;

            ThreadPool.QueueUserWorkItem(o =>
            {
                DataSet ds_Server = new DataSet();
                if (db.GetMailServer(0, 0, "*", "", "", ref ds_Server) && ds_Server.Tables[0].Rows.Count > 0)
                {
                    Hashtable ht = new Hashtable();
                    foreach (DataRow dr in ds_Server.Tables[0].Rows)
                    {
                        MailPara mp = new MailPara();
                        mp.name     = dr["名称"].ToString();
                        mp.address  = dr["地址"].ToString();
                        //mp.port = dr["端口"].ToString();
                        mp.user           = dr["用户"].ToString();
                        mp.password       = dr["密码"].ToString();
                        mp.from           = dr["送信人地址"].ToString();
                        mp.servertype     = dr["服务器类型"].ToString().Trim();
                        mp.attachement    = dr["添付文件"].ToString();
                        mp.isHtml         = dr["HTML"].ToString();
                        ht[mp.servertype] = mp;
                    }
                    DataSet ds      = new DataSet();
                    String strWhere = "送信状态='未送信'";
                    if (db.GetPublishVW(0, 0, "*", strWhere, "", ref ds))
                    {
                        int idx = 0;
                        while (idx < ds.Tables[0].Rows.Count)
                        {
                            if (workQueue_Outlook.getCount() < 5)
                            {
                                MailPara mp = getMailPara(ht, "OUTLOOK");
                                if (mp.servertype != null)
                                {
                                    mp = getMailPara(ds, idx, mp);
                                    workQueue_Outlook.EnqueueItem(mp);
                                    idx++;
                                    if (idx >= ds.Tables[0].Rows.Count)
                                    {
                                        break;
                                    }
                                }
                            }
                            if (workQueue_HotMail.getCount() < 5)
                            {
                                MailPara mp = getMailPara(ht, "HOTMAIL");
                                if (mp.servertype != null)
                                {
                                    mp = getMailPara(ds, idx, mp);
                                    workQueue_HotMail.EnqueueItem(mp);
                                    idx++;
                                    if (idx >= ds.Tables[0].Rows.Count)
                                    {
                                        break;
                                    }
                                }
                            }
                            if (workQueue_YMail.getCount() < 5)
                            {
                                MailPara mp = getMailPara(ht, "YAHOO");
                                if (mp.servertype != null)
                                {
                                    mp = getMailPara(ds, idx, mp);
                                    workQueue_YMail.EnqueueItem(mp);
                                    idx++;
                                    if (idx >= ds.Tables[0].Rows.Count)
                                    {
                                        break;
                                    }
                                }
                            }
                            if (workQueue_GMail.getCount() < 5)
                            {
                                MailPara mp = getMailPara(ht, "GMAIL");
                                if (mp.servertype != null)
                                {
                                    mp = getMailPara(ds, idx, mp);
                                    workQueue_GMail.EnqueueItem(mp);
                                    idx++;
                                    if (idx >= ds.Tables[0].Rows.Count)
                                    {
                                        break;
                                    }
                                }
                            }
                            if (workQueue_AMail.getCount() < 5)
                            {
                                MailPara mp = getMailPara(ht, "AOL");
                                if (mp.servertype != null)
                                {
                                    mp = getMailPara(ds, idx, mp);
                                    workQueue_AMail.EnqueueItem(mp);
                                    idx++;
                                    if (idx >= ds.Tables[0].Rows.Count)
                                    {
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            });
        }