Пример #1
0
        /// <summary>
        /// 只需传入一个MailMainBody对象,会自动拆分ReceiverStr,逐个发送
        /// </summary>
        /// <param name="MailMainBody">MailMainBody类的一个实例,用来进行参数传递</param>
        /// <returns>返回邮件ID数组</returns>
        public ArrayList MailSend(MailMainBody mailbody)
        {
            string[]  RecvAr     = System.Text.RegularExpressions.Regex.Split(mailbody.MailReceiverStr + mailbody.MailCcToAddr + mailbody.MailBccToAddr, ",");
            ArrayList listMailID = new ArrayList();
            string    RtnMailID  = "";

            // 发送一封邮件至发件人发件箱
            mailbody.MailFolderType = 2;
            mailbody.MailReceiver   = mailbody.MailSender;
            RtnMailID = Send(mailbody);
            listMailID.Add(RtnMailID);
            // 开始循环发送邮件
            for (int i = 0; i < RecvAr.Length - 1; i++)
            {
                mailbody.MailFolderType = 1;                 //收件箱
                mailbody.MailReceiver   = RecvAr[i].ToString();
                RtnMailID = Send(mailbody);
                if (RtnMailID != null)
                {
                    listMailID.Add(RtnMailID);
                }
            }
            mailbody = null;
            RecvAr   = null;
            return(listMailID);
        }
Пример #2
0
        /// <summary>
        /// 发信处理,包括邮件处理及附件处理
        /// </summary>
        private void btnSendMail_Click(object sender, System.EventArgs e)
        {
            HttpCookie UserCookie = Request.Cookies["Username"];

            Username = UserCookie.Value.ToString();
            MailClass    mailclass = new UDS.Components.MailClass();
            MailMainBody mailbody  = new UDS.Components.MailMainBody();
            ArrayList    listmail  = new ArrayList();
            ArrayList    upattlist = (ArrayList)Session["upattlist"];

            //	ArrayList listattfile = new ArrayList();
            // 得到mailbody类
            mailbody = ProcessFormPost();
            //邮件处理


            try
            {
                listmail = mailclass.MailSend(mailbody);                             // 返回已经发送的邮件ID列表(包括抄送和密抄)
                //	listattfile	 = AttUpload(mailbody.MailReceiverStr.ToString());   // 返回邮件附件数组
                foreach (string mailID in listmail)
                {                           // 循环发送邮件附件
                    foreach (UDS.Components.MailAttachFile att in upattlist)
                    {                       // 处理邮件附件的数据库操作部分
                        Random TempNameInt   = new Random();
                        string NewDocDirName = TempNameInt.Next(100000000).ToString();
                        Directory.CreateDirectory(Server.MapPath(".") + "\\AttachFiles\\" + Username + "\\" + NewDocDirName);
                        //File.Move(Server.MapPath(".")+"\\"+att.FileVisualPath ,Server.MapPath(".")+"\\AttachFiles\\"+Username+"\\"+NewDocDirName+"\\"+att.FileName);
                        File.Copy(Server.MapPath(".") + "\\" + att.FileVisualPath, Server.MapPath(".") + "\\AttachFiles\\" + Username + "\\" + NewDocDirName + "\\" + att.FileName, true);

                        //		Directory.Delete(Server.MapPath(".")+"\\"+att.FileVisualPath.ToString().Replace(att.FileName,""),true);
                        att.FileVisualPath = "\\AttachFiles\\" + Username + "\\" + NewDocDirName + "\\" + att.FileName;
                        mailclass.AttSend(att, Int32.Parse(mailID));
                    }
                }

                if (cblistAttribute.Items[1].Selected && Request.Form["hdnProjectID"].ToString() != "0")
                {
                    DocProcess(mailbody, upattlist);
                }

                Response.Write("<script language=javascript>alert('邮件发送成功!');if(parent.frames.length==0) window.close();else self.location=('Index.aspx');</script>");
            }
            catch (Exception sendex)
            {
                UDS.Components.Error.Log(sendex.ToString());
                Server.Transfer("../../Error.aspx");
            }
        }
Пример #3
0
        /// <summary>
        /// 发送邮件,只包括数据库操作
        /// </summary>
        /// <param name="mailbody">Mail类</param>
        public string Send(MailMainBody mailbody)
        {
            // create data object and params
            Database data   = new Database();
            string   MailID = null;

            SqlParameter[] prams =
            {
                data.MakeInParam("@MailFolderType",  SqlDbType.Int,          20, mailbody.MailFolderType),
                data.MakeInParam("@MailReceiverStr", SqlDbType.VarChar,     300, mailbody.MailReceiverStr),
                data.MakeInParam("@MailSendDate",    SqlDbType.DateTime,     20, DateTime.Parse(mailbody.MailSendDate)),
                data.MakeInParam("@MailSendLevel",   SqlDbType.SmallInt,     20, mailbody.MailSendLevel),
                data.MakeInParam("@MailSender",      SqlDbType.NVarChar,     20, mailbody.MailSender),
                data.MakeInParam("@MailReceiver",    SqlDbType.NVarChar,     20, mailbody.MailReceiver),
                data.MakeInParam("@MailSubject",     SqlDbType.NVarChar,     50, mailbody.MailSubject),
                data.MakeInParam("@MailBody",        SqlDbType.Text,     300000, mailbody.MailBody),
                data.MakeInParam("@MailCcToAddr",    SqlDbType.NVarChar,    300, mailbody.MailCcToAddr),
                data.MakeInParam("@MailBccToAddr",   SqlDbType.NVarChar,    300, mailbody.MailBccToAddr),
                data.MakeInParam("@MailReadFlag",    SqlDbType.Bit,           1, mailbody.MailReadFlag),
                data.MakeInParam("@MailTypeFlag",    SqlDbType.Bit,           1, mailbody.MailTypeFlag),
                data.MakeInParam("@MailClassID",     SqlDbType.Int,           1, mailbody.MailClassID),
                data.MakeInParam("@MailImportance",  SqlDbType.Int,           1, mailbody.MailImportance),
                data.MakeOutParam("@MailID",         SqlDbType.Int, 20)
            };

            try
            {
                data.RunProc("SP_MailSend", prams);
                MailID = prams[14].Value.ToString();
                if (MailID == string.Empty)
                {
                    return(null);
                }
                else
                {
                    return(MailID);
                }
            }
            catch (Exception ex)
            {
                Error.Log(ex.ToString());
                throw new Exception("邮件发送出错!", ex);
            }
        }
Пример #4
0
Файл: Mail.cs Проект: hoku85/UDS
        /// <summary>
        /// �����ʼ���ֻ�������ݿ����
        /// </summary>
        /// <param name="mailbody">Mail��</param>
        public string Send(MailMainBody mailbody)
        {
            // create data object and params
            Database data = new Database();
            string MailID = null;
            SqlParameter[] prams = {
                                       data.MakeInParam("@MailFolderType",  SqlDbType.Int, 20, mailbody.MailFolderType),
                                       data.MakeInParam("@MailReceiverStr",  SqlDbType.VarChar, 300, mailbody.MailReceiverStr),
                                       data.MakeInParam("@MailSendDate",  SqlDbType.DateTime, 20, DateTime.Parse(mailbody.MailSendDate)),
                                       data.MakeInParam("@MailSendLevel",  SqlDbType.SmallInt,20, mailbody.MailSendLevel),
                                       data.MakeInParam("@MailSender",  SqlDbType.NVarChar, 20, mailbody.MailSender),
                                       data.MakeInParam("@MailReceiver",  SqlDbType.NVarChar, 20, mailbody.MailReceiver),
                                       data.MakeInParam("@MailSubject",  SqlDbType.NVarChar, 50, mailbody.MailSubject),
                                       data.MakeInParam("@MailBody",  SqlDbType.Text , 300000, mailbody.MailBody),
                                       data.MakeInParam("@MailCcToAddr",  SqlDbType.NVarChar, 300, mailbody.MailCcToAddr),
                                       data.MakeInParam("@MailBccToAddr",  SqlDbType.NVarChar, 300, mailbody.MailBccToAddr),
                                       data.MakeInParam("@MailReadFlag",  SqlDbType.Bit, 1, mailbody.MailReadFlag),
                                       data.MakeInParam("@MailTypeFlag",  SqlDbType.Bit, 1, mailbody.MailTypeFlag),
                                       data.MakeInParam("@MailClassID",  SqlDbType.Int, 1, mailbody.MailClassID),
                                       data.MakeInParam("@MailImportance",  SqlDbType.Int, 1, mailbody.MailImportance),
                                       data.MakeOutParam("@MailID", SqlDbType.Int,20)
                                   };

            try
            {
                data.RunProc("SP_MailSend", prams);
                MailID = prams[14].Value.ToString();
                if (MailID == string.Empty )
                    return null;
                else
                    return MailID;
            }
            catch (Exception ex)
            {
                Error.Log(ex.ToString());
                throw new Exception("�ʼ����ͳ���!",ex);
            }
        }
Пример #5
0
Файл: Mail.cs Проект: hoku85/UDS
        /// <summary>
        /// ֻ�贫��һ��MailMainBody���󣬻��Զ����ReceiverStr,�������
        /// </summary>
        /// <param name="MailMainBody">MailMainBody���һ��ʵ�����������в�������</param>
        /// <returns>�����ʼ�ID����</returns>
        public ArrayList MailSend(MailMainBody mailbody)
        {
            string[] RecvAr = System.Text.RegularExpressions.Regex.Split(mailbody.MailReceiverStr +mailbody.MailCcToAddr +mailbody.MailBccToAddr ,",");
            ArrayList listMailID = new ArrayList();
            string RtnMailID = "";
            // ����һ���ʼ��������˷�����
            mailbody.MailFolderType = 2;
            mailbody.MailReceiver = mailbody.MailSender ;
            RtnMailID = Send(mailbody);
            listMailID.Add(RtnMailID);
            // ��ʼѭ�������ʼ�
            for(int i=0;i<RecvAr.Length-1;i++)
            {
                mailbody.MailFolderType = 1; //�ռ���
                mailbody.MailReceiver  = RecvAr[i].ToString();
                RtnMailID = Send(mailbody);
                if (RtnMailID!=null)
                {
                    listMailID.Add(RtnMailID);

                }
            }
            mailbody = null;
            RecvAr	 = null;
            return listMailID;
        }
Пример #6
0
        /// <summary>
        /// ���Ͳ������������ʼ�����
        /// </summary>
        private MailMainBody ProcessFormPost()
        {
            if(this.cblistAttribute.SelectedIndex.ToString()=="-1")
            {
                Response.Write("<script language=javascript>alert('��ѡ���ʼ�����!');history.go(-1);</script>");
                Response.End();
            }

            if(cblistAttribute.Items[1].Selected)
            {
                if(Request.Form["hdnProjectID"].ToString()=="0")
                {
                    Response.Write("<script language=javascript>alert('��ѡ��鵵��Ŀ!');history.go(-1);</script>");
                    Response.End();
                }

            }
            if(cblistAttribute.Items[0].Selected)
            {

                //���ǿ���֤
                if(Request.Form["hdnTxtSendTo"].ToString()=="")
                {
                    Response.Write("<script language=javascript>alert('��ѡ���ռ���!');history.go(-1);</script>");
                    Response.End();
                }

            }

            // ���������ݲ���
            MailMainBody mailbody		= new MailMainBody();
            //	string cID = "0";

            mailbody.MailFolderType		= 1; //�����ռ���
            mailbody.MailReceiverStr	= Request.Form["hdnTxtSendTo"].ToString();
            mailbody.MailSendDate		= DateTime.Now.ToString();
            mailbody.MailSendLevel		= 1;//default 1 Ԥ��
            mailbody.MailSender			= Username;
            mailbody.MailReceiver		= "";
            mailbody.MailSubject		= (txtSubject.Text=="")?"������":txtSubject.Text;
            mailbody.MailBody			= txtBody.Text.Replace("\r\n","<br/>");
            mailbody.MailCcToAddr		= Request.Form["hdnTxtCcTo"].ToString();
            mailbody.MailBccToAddr		= Request.Form["hdnTxtBccTo"].ToString();
            mailbody.MailReadFlag		= 0;
            mailbody.MailTypeFlag		= 1;
            mailbody.MailClassID        = Request.Form["hdnProjectID"].ToString()!=""?Int32.Parse(Request.Form["hdnProjectID"].ToString()):0;
            mailbody.MailImportance		= Int32.Parse(listImportance.SelectedItem.Value);

            //�����������
            if(this.cbRemind.Checked ==true)
            {
                SMS sm = new SMS();
                sm.SendMsg(Username,mailbody.MailReceiverStr+mailbody.MailCcToAddr+mailbody.MailBccToAddr,"����"+Username+"���յ���һ���µ��ʼ�",1,DateTime.Now,"",0,0);
                sm = null;
            }

            return mailbody;
        }
Пример #7
0
        /// <summary>
        /// �ĵ��������������ĵ��������������
        /// </summary>
        private void DocProcess(MailMainBody mailbody,ArrayList upattlist)
        {
            string DocID = "";
            int cstRightToApproveDocument = 2;
            ProjectClass pjt = new ProjectClass();
            DocBody docbody = new DocBody();
            docbody.DocTitle			= mailbody.MailSubject;
            docbody.DocContent			= mailbody.MailBody;
            docbody.DocAddedBy			= mailbody.MailSender;
            docbody.DocClassID			= mailbody.MailClassID;
            docbody.DocAddedDate        = DateTime.Now.ToString();
            docbody.DocApprover			= (pjt.GetAccessPermission(Int32.Parse(ClassID),Username,cstRightToApproveDocument))?Username:"";
            docbody.DocApproveDate		= (pjt.GetAccessPermission(Int32.Parse(ClassID),Username,cstRightToApproveDocument))?DateTime.Now.ToString():"";
            docbody.DocApproved         = (docbody.DocApprover =="")?0:1;
            docbody.DocAttribute        = 0;
            docbody.DocType				= 0;

            DocumentClass doc = new DocumentClass();
            // ����ĵ�,������ID

            DocID = doc.AddDocBody(docbody);
            foreach(UDS.Components.MailAttachFile  att in upattlist)
            {
                try
                {
                    DocAttachFile docatt = new DocAttachFile();
                    //  Mail Attach File ��ת��ΪDoc Attach File
                    docatt.FileAttribute  = 0;
                    docatt.FileSize       = att.FileSize;
                    docatt.FileName	      = att.FileName;
                    docatt.FileAuthor     = Username;
                    docatt.FileCatlog     = "�ĵ�";
                    docatt.FileVisualPath = "Mail"+att.FileVisualPath;
                    docatt.FileAddedDate  = DateTime.Now.ToString();
                    docatt.DocID          = Int32.Parse(DocID);
                    // ת������

                    // �������ݿ⴦��
                    doc.AddAttach(docatt,Int32.Parse(DocID));

                }
                catch(Exception ioex)
                {
                    UDS.Components.Error.Log(ioex.ToString());
                    Server.Transfer("../../Error.aspx");
                }
            }
        }
Пример #8
0
        /// <summary>
        /// ���Ŵ���������ʼ��������������
        /// </summary>
        private void btnSendMail_Click(object sender, System.EventArgs e)
        {
            HttpCookie UserCookie = Request.Cookies["Username"];
                Username = Server.UrlDecode(Request.Cookies["UserName"].Value);
                MailClass mailclass   = new UDS.Components.MailClass();
                MailMainBody mailbody = new UDS.Components.MailMainBody();
                ArrayList listmail    = new ArrayList();
                ArrayList upattlist = (ArrayList)Session["upattlist"];
            //	ArrayList listattfile = new ArrayList();
                // �õ�mailbody��
                mailbody = ProcessFormPost();
                //�ʼ�����

                try
                {
                    listmail     = mailclass.MailSend(mailbody); // �����Ѿ����͵��ʼ�ID�б�(�������ͺ��ܳ�)
                //	listattfile	 = AttUpload(mailbody.MailReceiverStr.ToString());   // �����ʼ���������
                    foreach(string mailID in listmail)
                    {   // ѭ�������ʼ�����
                        foreach(UDS.Components.MailAttachFile att in upattlist)
                        {   //�������ʼ����������ݿ��������

                            Random TempNameInt    = new Random();
                            string NewDocDirName  = TempNameInt.Next(100000000).ToString();
                            Directory.CreateDirectory(Server.MapPath(".")+"\\AttachFiles\\"+Username+"\\"+NewDocDirName);
                            //File.Move(Server.MapPath(".")+"\\"+att.FileVisualPath ,Server.MapPath(".")+"\\AttachFiles\\"+Username+"\\"+NewDocDirName+"\\"+att.FileName);
                            File.Copy(Server.MapPath(".")+"\\"+att.FileVisualPath ,Server.MapPath(".")+"\\AttachFiles\\"+Username+"\\"+NewDocDirName+"\\"+att.FileName,true);

                            //		Directory.Delete(Server.MapPath(".")+"\\"+att.FileVisualPath.ToString().Replace(att.FileName,""),true);
                            att.FileVisualPath    = "\\AttachFiles\\"+Username+"\\"+NewDocDirName+"\\"+att.FileName;
                            mailclass.AttSend(att,Int32.Parse(mailID));
                        }
                    }

                    if(cblistAttribute.Items[1].Selected&&Request.Form["hdnProjectID"].ToString()!="0")
                    {
                        DocProcess(mailbody,upattlist);
                    }

                    Response.Write("<script language=javascript>alert('�ʼ����ͳɹ�!');if(parent.frames.length==0) window.close();else self.location=('Index.aspx');</script>");
                }
                catch (Exception sendex)
                {
                    UDS.Components.Error.Log(sendex.ToString());
                    Server.Transfer("../../Error.aspx");
                }
        }