private void BatchSendEmail_Click(object sender, EventArgs e)
        {
            #region 批量发送邮件

            if (this.CheckCookie())
            {
                groupidlist = Usergroups.GetSelectString(",");

                if (groupidlist == "" && usernamelist.Text.Trim() == "")
                {
                    base.RegisterStartupScript("", "<script>alert('您需要输入接收邮件用户名称或选取相关的用户组,因此邮件无法发送');</script>");
                    return;
                }

                int percount = 5; //每多少记录为一次等待

                //发送用户列表邮件
                if (usernamelist.Text.Trim() != "")
                {
                    DataTable dt = Users.GetEmailListByUserNameList(usernamelist.Text);
                    if (dt.Rows.Count <= 0)
                    {
                        base.RegisterStartupScript("", "<script>alert('您输入的接收邮件用户名未能查找到相关用户,因此邮件无法发送');</script>");
                        return;
                    }
                    Thread[] lThreads = new Thread[dt.Rows.Count];
                    int      count    = 0;

                    foreach (DataRow dr in dt.Rows)
                    {
                        EmailMultiThread emt = new EmailMultiThread(dr["UserName"].ToString(), dr["Email"].ToString(), subject.Text, body.Text);
                        lThreads[count] = new Thread(new ThreadStart(emt.Send));
                        lThreads[count].Start();

                        if (count >= percount)
                        {
                            Thread.Sleep(5000);
                            count = 0;
                        }
                        count++;
                    }
                }

                if (groupidlist == "")
                {
                    base.LoadRegisterStartupScript("PAGE", "window.location.href='global_usergroupsendemail.aspx';");
                    return;
                }
                ClientScript.RegisterStartupScript(this.GetType(), "Page", "<script>submit_Click();</script>");
            }

            #endregion
        }
        private void ExportUserEmails()
        {
            string groupidlist = "";

            if (this.CheckCookie())
            {
                groupidlist = Usergroups.GetSelectString(",");
            }


            if (groupidlist == "")
            {
                return;
            }

            DataTable dt = Users.GetEmailListByGroupidList(groupidlist);

            string words = "";

            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    words += dt.Rows[i][1].ToString().Trim() + "; ";
                }
            }

            string filename = "Useremail.txt";

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Buffer          = false;
            HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
            HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + Server.UrlEncode(filename));
            HttpContext.Current.Response.ContentType = "text/plain";
            this.EnableViewState = false;
            HttpContext.Current.Response.Write(words);
            HttpContext.Current.Response.End();
        }
        private void BatchSendSM_Click(object sender, EventArgs e)
        {
            #region 批量短消息发送

            if (this.CheckCookie())
            {
                groupidlist = Usergroups.GetSelectString(",");

                if (groupidlist == "")
                {
                    base.RegisterStartupScript("", "<script>alert('请您先选取相关的用户组,再点击提交按钮');</script>");
                    return;
                }

#if EntLib
                if (RabbitMQConfigs.GetConfig() != null && RabbitMQConfigs.GetConfig().SendShortMsg.Enable)//当开启errlog错误日志记录功能时
                {
                    PrivateMessageInfo pm = new PrivateMessageInfo()
                    {
                        Msgfrom      = username.Replace("'", "''"),
                        Msgfromid    = userid,
                        Folder       = int.Parse(folder.SelectedValue),
                        Subject      = subject.Text,
                        Postdatetime = Discuz.Common.Utils.GetDateTime(), //获取发送消息的系统时间
                        Message      = message.Text,
                        New          = 1                                  //标记为未读
                    };
                    Discuz.EntLib.ServiceBus.SendShortMsgClientHelper.GetSendShortMsgClient().AsyncSendShortMsgByUserGroup(groupidlist, pm);
                    return;
                }
#endif
                ClientScript.RegisterStartupScript(this.GetType(), "Page", "<script>submit_Click();</script>");
            }

            #endregion
        }
Ejemplo n.º 4
0
        private void BatchSendSM_Click(object sender, EventArgs e)
        {
            #region 批量短消息发送

            if (this.CheckCookie())
            {
                string groupidlist = Usergroups.GetSelectString(",");

                if (groupidlist == "")
                {
                    base.RegisterStartupScript("", "<script>alert('请您先选取相关的用户组,再点击提交按钮');</script>");
                    return;
                }

#if EntLib
                if (RabbitMQConfigs.GetConfig() != null && RabbitMQConfigs.GetConfig().SendShortMsg.Enable)//当开启errlog错误日志记录功能时
                {
                    PrivateMessageInfo pm = new PrivateMessageInfo()
                    {
                        Msgfrom      = username.Replace("'", "''"),
                        Msgfromid    = userid,
                        Folder       = int.Parse(folder.SelectedValue),
                        Subject      = subject.Text,
                        Postdatetime = Discuz.Common.Utils.GetDateTime(), //获取发送消息的系统时间
                        Message      = message.Text,
                        New          = 1                                  //标记为未读
                    };
                    Discuz.EntLib.ServiceBus.SendShortMsgClientHelper.GetSendShortMsgClient().AsyncSendShortMsgByUserGroup(groupidlist, pm);
                }
#else
                int percount = Discuz.Common.Utils.StrToInt(postcountpercircle.Text, 100); //每多少记录为一次等待
                int count    = 0;                                                          //当前记录数

                //foreach (DataRow dr in DbHelper.ExecuteDataset("SELECT [uid] ,[username]  From [" + BaseConfigs.GetTablePrefix + "users] WHERE [groupid] IN(" + groupidlist + ")").Tables[0].Rows)
                foreach (DataRow dr in Users.GetUserListByGroupidList(groupidlist).Rows)
                {
                    //DbHelper.ExecuteNonQuery("INSERT INTO [" + BaseConfigs.GetTablePrefix + "pms] (msgfrom,msgfromid,msgto,msgtoid,folder,new,subject,postdatetime,message) VALUES ('" + this.username.Replace("'", "''") + "','" + this.userid.ToString() + "','" + dr["username"].ToString().Replace("'", "''") + "','" + dr["uid"].ToString() + "','" + folder.SelectedValue + "','1','" + subject.Text + "','" + postdatetime.Text + "','" + message.Text + "')");
                    //DbHelper.ExecuteNonQuery("UPDATE [" + BaseConfigs.GetTablePrefix + "users] SET [newpmcount]=[newpmcount]+1  WHERE [uid] =" + dr["uid"].ToString());
                    //Discuz.Data.DatabaseProvider.GetInstance().SendPMToUser(username.Replace("'", "''"), userid, dr["username"].ToString().Replace("'", "''"), Convert.ToInt32(dr["uid"].ToString()), int.Parse(folder.SelectedValue), subject.Text, Convert.ToDateTime(postdatetime.Text), message.Text);
                    PrivateMessageInfo pm = new PrivateMessageInfo();
                    pm.Msgfrom      = username.Replace("'", "''");
                    pm.Msgfromid    = userid;
                    pm.Msgto        = dr["username"].ToString().Replace("'", "''");
                    pm.Msgtoid      = Convert.ToInt32(dr["uid"].ToString());
                    pm.Folder       = int.Parse(folder.SelectedValue);
                    pm.Subject      = subject.Text;
                    pm.Postdatetime = postdatetime.Text;
                    pm.Message      = message.Text;
                    pm.New          = 1;//标记为未读
                    PrivateMessages.CreatePrivateMessage(pm, 0);
                    if (count >= percount)
                    {
                        Thread.Sleep(500);
                        count = 0;
                    }
                    count++;
                }
#endif
                base.RegisterStartupScript("PAGE", "window.location.href='global_sendSMtogroup.aspx';");
            }

            #endregion
        }
Ejemplo n.º 5
0
        private void BatchSendEmail_Click(object sender, EventArgs e)
        {
            #region 批量发送邮件

            if (this.CheckCookie())
            {
                string groupidlist = Usergroups.GetSelectString(",");

                if ((groupidlist == "") && (usernamelist.Text.Trim() == ""))
                {
                    base.RegisterStartupScript("", "<script>alert('您需要输入接收邮件用户名称或选取相关的用户组,因此邮件无法发送');</script>");
                    return;
                }

                int percount = 5; //每多少记录为一次等待

                //发送用户列表邮件
                if (usernamelist.Text.Trim() != "")
                {
                    //string strwhere = " WHERE [Email] Is Not null AND (";
                    //foreach (string username in usernamelist.Text.Split(','))
                    //{
                    //    if (username.Trim() != "")
                    //        strwhere += " [username] like '%" + username.Trim() + "%' OR ";
                    //}
                    //strwhere = strwhere.Substring(0, strwhere.Length - 3) + ")";

                    //DataTable dt = DbHelper.ExecuteDataset("SELECT [username],[Email]  From [" + BaseConfigs.GetTablePrefix + "users] " + strwhere).Tables[0];
                    DataTable dt = Users.GetEmailListByUserNameList(usernamelist.Text);
                    if (dt.Rows.Count <= 0)
                    {
                        base.RegisterStartupScript("", "<script>alert('您输入的接收邮件用户名未能查找到相关用户,因此邮件无法发送');</script>");
                        return;
                    }
                    base.LoadRegisterStartupScript("PAGE", "window.location.href='global_usergroupsendemail.aspx';");

                    Thread[] lThreads = new Thread[dt.Rows.Count];
                    int      count    = 0;

                    foreach (DataRow dr in dt.Rows)
                    {
                        EmailMultiThread emt = new EmailMultiThread(dr["UserName"].ToString(), dr["Email"].ToString(), subject.Text, body.Text);
                        lThreads[count] = new Thread(new ThreadStart(emt.Send));
                        lThreads[count].Start();

                        if (count >= percount)
                        {
                            Thread.Sleep(5000);
                            count = 0;
                        }
                        count++;

                        //ThreadPool.QueueUserWorkItem(new WaitCallback(SendMail),string.Format("http://bbs.ent.tom.com/forum/view_thread.php?forumid=1&threadid={0}&backurl=http%3A%2F%2Fbbs.ent.tom.com%2Fforum%2Flist_thread.php%3Fforumid%3D1%26page%3D1%26sort%3D0",PageNumber.ToString()));
                    }
                }

                //发送用户组邮件
                if (groupidlist != "")
                {
                    //DataTable dt = DbHelper.ExecuteDataset("SELECT [username],[Email]  From [" + BaseConfigs.GetTablePrefix + "users] WHERE [Email] Is Not null AND [Email]<>'' AND [groupid] IN(" + groupidlist + ")").Tables[0];
                    DataTable dt       = Users.GetEmailListByGroupidList(groupidlist);
                    Thread[]  lThreads = new Thread[dt.Rows.Count];
                    int       count    = 0;

                    foreach (DataRow dr in dt.Rows)
                    {
                        EmailMultiThread emt = new EmailMultiThread(dr["UserName"].ToString(), dr["Email"].ToString(), subject.Text, body.Text);
                        lThreads[count] = new Thread(new ThreadStart(emt.Send));
                        lThreads[count].Start();

                        if (count >= percount)
                        {
                            Thread.Sleep(5000);
                            count = 0;
                        }
                        count++;

                        //ThreadPool.QueueUserWorkItem(new WaitCallback(SendMail),string.Format("http://bbs.ent.tom.com/forum/view_thread.php?forumid=1&threadid={0}&backurl=http%3A%2F%2Fbbs.ent.tom.com%2Fforum%2Flist_thread.php%3Fforumid%3D1%26page%3D1%26sort%3D0",PageNumber.ToString()));
                    }
                }
                base.RegisterStartupScript("PAGE", "window.location.href='global_usergroupsendemail.aspx';");
            }

            #endregion
        }