コード例 #1
0
    public void display()
    {
        //需要首先设置这些信息
        HyoaClass.Hyoa_mail_config Hyoa_mail_config = new HyoaClass.Hyoa_mail_config();
        DataTable dtconfig = Hyoa_mail_config.Getmailconfigbyuserid(this.Session["hyuid"].ToString());
        if (dtconfig.Rows.Count > 0)
        {
            string pop3Server = dtconfig.Rows[0]["hy_pop3url"].ToString();// "pop.163.com";    //邮箱服务器 如:"pop.sina.com.cn";或 "pop.qq.com" 好像sina的比较快
            int pop3Port = System.Int32.Parse(dtconfig.Rows[0]["hy_pop3port"].ToString()); //110;          //端口号码   用"110"好使。最好看一下你的邮箱服务器用的是什么端口号
            bool pop3UseSsl = false;
            string lsmailid = dtconfig.Rows[0]["hy_mailid"].ToString();
            string username = lsmailid.Substring(0, lsmailid.IndexOf("@"));//"ztmfang2008";        //你的邮箱用户名
            string password = Decrypt(dtconfig.Rows[0]["hy_mailpwd"].ToString()); //"20120328";      //你的邮箱密码
            List<string> gotEmailIds = new List<string>();
            List<Mime> result = new List<Mime>();
            using (POP3_Client pop3 = new POP3_Client())
            {
                //与Pop3服务器建立连接
                pop3.Connect(pop3Server, pop3Port, pop3UseSsl);
                //验证身份
                pop3.Authenticate(username, password, false);
                //获取邮件信息列表
                POP3_ClientMessageCollection infos = pop3.Messages;
                foreach (POP3_ClientMessage info in infos)
                {
                    //每封Email会有一个在Pop3服务器范围内唯一的Id,检查这个Id是否存在就可以知道以前有没有接收过这封邮件
                    if (gotEmailIds.Contains(info.UID))
                        continue;
                    //获取这封邮件的内容
                    byte[] bytes = info.MessageToByte();
                    //记录这封邮件的Id
                    gotEmailIds.Add(info.UID);
                    //this.Response.Write("<script>alert('" + info.UID + "');</script>");
                    //解析从Pop3服务器发送过来的邮件信息
                    Mime m = Mime.Parse(bytes);

                    HyoaClass.Hyoa_global Hyoa_global = new HyoaClass.Hyoa_global();
                    HyoaClass.Hyoa_mail Hyoa_mail = new HyoaClass.Hyoa_mail();
                    HyoaClass.Hyoa_fileatt Hyoa_fileatt = new HyoaClass.Hyoa_fileatt();
                    //this.Response.Write("<script>alert('aaa');</script>");
                    string lsid = Hyoa_global.GetRandom();
                    string lsdocid = info.UID.ToString();

                    DataTable dtmail = Hyoa_mail.Getmailbydocid(lsdocid);
                    if (dtmail.Rows.Count > 0)
                    { }
                    else
                    {
                        Hyoa_mail.ID = lsid;
                        Hyoa_mail.DOCID = lsdocid;
                        Hyoa_mail.hy_type = "收件";
                        Hyoa_mail.hy_foldername = "收件箱";
                        Hyoa_mail.hy_fsrid = m.MainEntity.From.ToAddressListString().ToString();
                        Hyoa_mail.hy_fsrname = m.MainEntity.From.ToAddressListString().ToString();
                        Hyoa_mail.hy_jsrid = this.Session["hyuid"].ToString();
                        Hyoa_mail.hy_wbjsrid = m.MainEntity.To.ToAddressListString().ToString();
                        Hyoa_mail.hy_jsrname = this.Session["hyuname"].ToString();
                        Hyoa_mail.hy_title = m.MainEntity.Subject.ToString();
                        Hyoa_mail.hy_body = m.BodyHtml.ToString();
                        Hyoa_mail.hy_datetime = m.MainEntity.Date.ToString();
                        Hyoa_mail.hy_ifsavetofjx = "";
                        Hyoa_mail.hy_yxj = "";
                        Hyoa_mail.hy_yjbg = "";
                        Hyoa_mail.hy_zycd = "";
                        Hyoa_mail.hy_hz = "";

                        Hyoa_mail.Insert();
                        //this.Response.Write("<script>alert('bbb');</script>");

                        //获取附件
                        foreach (MimeEntity entry in m.Attachments)
                        {
                            string lsfileattid = Hyoa_global.GetRandom();
                            string fileName = entry.ContentDisposition_FileName; //获取文件名称
                            string path = Server.MapPath("~\\fileatt\\" + lsfileattid);
                            Directory.CreateDirectory(path);
                            path += "\\" + fileName;
                            if (File.Exists(path))
                            {
                                Random random = new Random();
                                int newfile = random.Next(1, 100000);
                                path = Server.MapPath("~\\fileatt\\" + lsfileattid + "\\" + newfile.ToString());
                                Directory.CreateDirectory(path);
                                path += "\\" + fileName;
                            }
                            byte[] data = entry.Data;
                            FileStream pFileStream = null;
                            pFileStream = new FileStream(path, FileMode.Create);
                            pFileStream.Write(data, 0, data.Length);
                            pFileStream.Close();

                            //向附件表插入记录
                            Hyoa_fileatt.ID = lsfileattid;
                            Hyoa_fileatt.hy_fatherid = lsdocid;
                            Hyoa_fileatt.hy_filename = fileName;
                            Hyoa_fileatt.hy_filepath = path.Substring(path.IndexOf("fileatt\\"));
                            Hyoa_fileatt.hy_filesize = data.Length.ToString();
                            Hyoa_fileatt.hy_userid = this.Session["hyuid"].ToString();
                            Hyoa_fileatt.hy_djsj = m.MainEntity.Date.ToString();
                            Hyoa_fileatt.hy_fatherfield = "";
                            Hyoa_fileatt.Insert();

                            //this.Response.Write("<script>alert('ccc');</script>");
                        }
                    }
                    //Response.Write("<br>From:" + m.MainEntity.From.ToAddressListString());
                    //Response.Write("<br>To:" + m.MainEntity.To.ToAddressListString());
                    //Response.Write("<br>Time:" + m.MainEntity.Date);            //发送时间
                    //Response.Write("<br>Subject:" + m.MainEntity.Subject);      //主题
                    //Response.Write("<br>Plain Body:" + m.BodyText);             //内容
                    //Response.Write("<br>Html Body:" + m.BodyHtml);              //HTML格式内容
                }
                this.Response.Write("<script>alert('邮件接收完成!');window.opener.location.reload();window.close();</script>");
            }
        }
        else
        {
            this.Response.Write("<script>alert('请先配置外网邮件信息!');</script>");
        }
    }
コード例 #2
0
ファイル: main_mail.aspx.cs プロジェクト: wjszxli/Webapp
    //保存
    protected void Button_Save_Click(object sender, EventArgs e)
    {
        if (this.Session["hyuid"].ToString() == "")
            this.Response.Redirect("/login.aspx");

        string ls_tip = "发送成功!";

        HyoaClass.Hyoa_mail Hyoa_mail = new HyoaClass.Hyoa_mail();
        HyoaClass.Hyoa_global Hyoa_global = new HyoaClass.Hyoa_global();

        //发送
        if (this.txtwhichoperation.Value == "1")
        {
            string[] lv_jsrid = this.txthy_jsrid.Text.Split('+');
            string[] lv_jsrname = this.txthy_jsrname.Value.Split('+');
            for (var i = 0; i < lv_jsrid.Length; i++)
            {
                if (lv_jsrid[i] != "")
                {
                    Hyoa_mail.ID = Hyoa_global.GetRandom();
                    Hyoa_mail.DOCID = this.txtdocid.Value;
                    Hyoa_mail.hy_type = "收件";
                    Hyoa_mail.hy_foldername = "收件箱";
                    Hyoa_mail.hy_fsrid = this.lblhy_fsrid.Text;
                    Hyoa_mail.hy_fsrname = this.lblhy_fsrname.Text;
                    Hyoa_mail.hy_jsrid = lv_jsrid[i].ToString();
                    Hyoa_mail.hy_wbjsrid = "";
                    Hyoa_mail.hy_jsrname = lv_jsrname[i].ToString();
                    Hyoa_mail.hy_title = this.txthy_title.Text;
                    Hyoa_mail.hy_body = this.hy_content1.Value;
                    Hyoa_mail.hy_datetime = System.DateTime.Now.ToString();
                    Hyoa_mail.hy_ifsavetofjx = "";
                    Hyoa_mail.hy_yxj = "";
                    Hyoa_mail.hy_yjbg = "";
                    Hyoa_mail.hy_zycd = "";
                    Hyoa_mail.hy_hz = "";
                    Hyoa_mail.hy_wbjszh = "";
                    Hyoa_mail.Insert();
                }
                if (this.txthy_wbjsrid.Text != "")
                {
                    sendmail(this.txthy_wbjsrid.Text, this.txthy_title.Text, this.hy_content1.Value, this.txtdocid.Value);
                }

            }
            //如果要保存到发件箱,则保存一份
            if (this.ddlifsavetofjx.SelectedValue == "是")
            {
                Hyoa_mail.ID = Hyoa_global.GetRandom();
                Hyoa_mail.DOCID = this.txtdocid.Value;
                Hyoa_mail.hy_type = "发件";
                Hyoa_mail.hy_foldername = "发件箱";
                Hyoa_mail.hy_fsrid = this.lblhy_fsrid.Text;
                Hyoa_mail.hy_fsrname = this.lblhy_fsrname.Text;
                Hyoa_mail.hy_jsrid = this.txthy_jsrid.Text;
                Hyoa_mail.hy_wbjsrid = this.txthy_wbjsrid.Text;
                Hyoa_mail.hy_jsrname = this.txthy_jsrname.Value;
                Hyoa_mail.hy_title = this.txthy_title.Text;
                Hyoa_mail.hy_body = this.hy_content1.Value;
                Hyoa_mail.hy_datetime = System.DateTime.Now.ToString();
                Hyoa_mail.hy_ifsavetofjx = this.ddlifsavetofjx.SelectedValue;
                Hyoa_mail.hy_yxj = "";
                Hyoa_mail.hy_yjbg = "";
                Hyoa_mail.hy_zycd = "";
                Hyoa_mail.hy_hz = "";
                Hyoa_mail.hy_wbjszh = "";
                Hyoa_mail.Insert();
            }
        }

        //存草稿
        if (this.txtwhichoperation.Value == "2")
        {
            if (this.txtop.Value == "add")
            {
                string ls_id = this.txtdocid.Value;
                Hyoa_mail.ID = ls_id;
                this.txtid.Value = ls_id;
                Hyoa_mail.DOCID = this.txtdocid.Value;
                Hyoa_mail.hy_type = "发件";
                Hyoa_mail.hy_foldername = "草稿箱";
                Hyoa_mail.hy_fsrid = this.lblhy_fsrid.Text;
                Hyoa_mail.hy_fsrname = this.lblhy_fsrname.Text;
                Hyoa_mail.hy_jsrid = this.txthy_jsrid.Text;
                Hyoa_mail.hy_wbjsrid = this.txthy_wbjsrid.Text;
                Hyoa_mail.hy_jsrname = this.txthy_jsrname.Value;
                Hyoa_mail.hy_title = this.txthy_title.Text;
                Hyoa_mail.hy_body = this.hy_content1.Value;
                Hyoa_mail.hy_datetime = System.DateTime.Now.ToString();
                Hyoa_mail.hy_ifsavetofjx = this.ddlifsavetofjx.SelectedValue;
                Hyoa_mail.hy_yxj = "";
                Hyoa_mail.hy_yjbg = "";
                Hyoa_mail.hy_zycd = "";
                Hyoa_mail.hy_hz = "";
                Hyoa_mail.hy_wbjszh = "";
                Hyoa_mail.Insert();
                ls_tip = "存草稿成功!";
            }
            else
            {
                string ls_id = this.txtid.Value;
                Hyoa_mail.ID = ls_id;
                this.txtid.Value = ls_id;
                Hyoa_mail.DOCID = this.txtdocid.Value;
                Hyoa_mail.hy_type = "发件";
                Hyoa_mail.hy_foldername = "草稿箱";
                Hyoa_mail.hy_fsrid = this.lblhy_fsrid.Text;
                Hyoa_mail.hy_fsrname = this.lblhy_fsrname.Text;
                Hyoa_mail.hy_jsrid = this.txthy_jsrid.Text;
                Hyoa_mail.hy_wbjsrid = this.txthy_wbjsrid.Text;
                Hyoa_mail.hy_jsrname = this.txthy_jsrname.Value;
                Hyoa_mail.hy_title = this.txthy_title.Text;
                Hyoa_mail.hy_body = this.hy_content1.Value;
                Hyoa_mail.hy_datetime = System.DateTime.Now.ToString();
                Hyoa_mail.hy_ifsavetofjx = this.ddlifsavetofjx.SelectedValue;
                Hyoa_mail.hy_yxj = "";
                Hyoa_mail.hy_yjbg = "";
                Hyoa_mail.hy_zycd = "";
                Hyoa_mail.hy_hz = "";
                Hyoa_mail.hy_wbjszh = "";
                Hyoa_mail.Update();
                ls_tip = "存草稿成功!";
            }
        }
        //处理完成后的提示及跳转(增加刷新附件功能)
        if (this.txtifsxfj.Text == "1")
        {
            Response.Write("<script>window.location='main_mail.aspx?op=modify&mid=" + this.txtmudelid.Value + "&id=" + this.txtid.Value + "&url=" + this.txturl.Value + "'</script>");
        }
        else
        {
            Response.Write("<script>alert('" + ls_tip + "');window.location='" + this.txturl.Value + "'</script>");
        }
    }
コード例 #3
0
ファイル: list_mail_cgx.aspx.cs プロジェクト: wjszxli/Webapp
 protected void btnsendinfo_Click(object sender, EventArgs e)
 {
     HyoaClass.Hyoa_mail Hyoa_mail = new HyoaClass.Hyoa_mail();
     HyoaClass.Hyoa_global Hyoa_global = new HyoaClass.Hyoa_global();
     String[] v_uids = this.txtuids.Value.Split(',');
     for (var i = 0; i < v_uids.Length; i++)
     {
         if (v_uids[i] != "")
         {
             DataTable dt = Hyoa_mail.Getmail(v_uids[i]);
             if (dt.Rows.Count > 0)
             {
                 //考虑多人情况
                 String[] v_jsrids = dt.Rows[0]["hy_jsrid"].ToString().Split('+');
                 String[] v_jsrnames = dt.Rows[0]["hy_jsrname"].ToString().Split('+');
                 for (var j = 0; j < v_jsrids.Length; j++)
                 {
                     if (v_jsrids[j] != "")
                     {
                         //发送
                         Hyoa_mail.ID = Hyoa_global.GetRandom();
                         Hyoa_mail.DOCID = dt.Rows[0]["ID"].ToString();
                         Hyoa_mail.hy_type = "收件";
                         Hyoa_mail.hy_foldername = "收件箱";
                         Hyoa_mail.hy_fsrid = Session["hyuid"].ToString();
                         Hyoa_mail.hy_fsrname = Session["hyuname"].ToString();
                         Hyoa_mail.hy_jsrid = v_jsrids[j];
                         Hyoa_mail.hy_wbjsrid = "";
                         Hyoa_mail.hy_jsrname = v_jsrnames[j];
                         Hyoa_mail.hy_title = dt.Rows[0]["hy_title"].ToString();
                         Hyoa_mail.hy_body = dt.Rows[0]["hy_body"].ToString();
                         Hyoa_mail.hy_datetime = System.DateTime.Now.ToString();
                         Hyoa_mail.hy_ifsavetofjx = "";
                         Hyoa_mail.hy_yxj = "";
                         Hyoa_mail.hy_yjbg = "";
                         Hyoa_mail.hy_zycd = "";
                         Hyoa_mail.hy_hz = "";
                         Hyoa_mail.Insert();
                     }
                     if (dt.Rows[0]["hy_wbjsrid"].ToString() != "")
                     {
                         sendmail(dt.Rows[0]["hy_wbjsrid"].ToString(), dt.Rows[0]["hy_title"].ToString(), dt.Rows[0]["hy_body"].ToString(), dt.Rows[0]["ID"].ToString());
                     }
                 }
             }
         }
     }
     this.txtuids.Value = "";
     //DataPlay(1);
     Response.Write("<script>alert('发送成功!');</script>");
     DataPlay(System.Int32.Parse(this.curpage.Text));
 }
コード例 #4
0
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //保存
    protected void Button_Save_Click(object sender, EventArgs e)
    {
        if (this.Session["hyuid"].ToString() == "")
            this.Response.Redirect("../login.aspx");

        string ls_tip = "发送成功!";

        HyoaClass.Hyoa_mail Hyoa_mail = new HyoaClass.Hyoa_mail();
        HyoaClass.Hyoa_global Hyoa_global = new HyoaClass.Hyoa_global();

        //发送
        if (this.txtwhichoperation.Value == "1")
        {
            string[] lv_jsrid = this.txthy_jsrid.Value.Split('+');
            string[] lv_jsrname = this.txthy_jsrname.Value.Split('+');
            for (var i = 0; i < lv_jsrid.Length; i++)
            {
                if (lv_jsrid[i] != "")
                {
                    Hyoa_mail.ID = Hyoa_global.GetRandom();
                    if (Request.QueryString["zfid"] == null)
                    {
                        Hyoa_mail.DOCID = this.txtdocid.Value;
                    }
                    else
                    {
                        Hyoa_mail.DOCID = this.txtid.Value;
                    }
                    Hyoa_mail.hy_type = "收件";
                    Hyoa_mail.hy_foldername = "收件箱";
                    Hyoa_mail.hy_fsrid = Session["hyuid"].ToString();
                    Hyoa_mail.hy_fsrname = Session["hyuname"].ToString();
                    Hyoa_mail.hy_jsrid = lv_jsrid[i].ToString();
                    Hyoa_mail.hy_wbjsrid = "";
                    Hyoa_mail.hy_jsrname = lv_jsrname[i].ToString();
                    Hyoa_mail.hy_title = this.hy_title.Text;
                    Hyoa_mail.hy_body = this.hy_body.Text;
                    Hyoa_mail.hy_datetime = System.DateTime.Now.ToString();
                    Hyoa_mail.hy_ifsavetofjx = "";
                    Hyoa_mail.hy_yxj = "";
                    Hyoa_mail.hy_yjbg = "";
                    Hyoa_mail.hy_zycd = "";
                    Hyoa_mail.hy_hz = "";
                    Hyoa_mail.Insert();
                }
            }
            //如果要保存到发件箱,则保存一份
            if (this.ddlifsavetofjx.SelectedValue == "是")
            {
                Hyoa_mail.ID = Hyoa_global.GetRandom();
                Hyoa_mail.DOCID = this.txtdocid.Value;
                Hyoa_mail.hy_type = "发件";
                Hyoa_mail.hy_foldername = "发件箱";
                Hyoa_mail.hy_fsrid = Session["hyuid"].ToString();
                Hyoa_mail.hy_fsrname = Session["hyuname"].ToString();
                Hyoa_mail.hy_jsrid = this.txthy_jsrid.Value;
                Hyoa_mail.hy_wbjsrid = "";
                Hyoa_mail.hy_jsrname = this.txthy_jsrname.Value;
                Hyoa_mail.hy_title = this.hy_title.Text;
                Hyoa_mail.hy_body = this.hy_body.Text;
                Hyoa_mail.hy_datetime = System.DateTime.Now.ToString();
                Hyoa_mail.hy_ifsavetofjx = this.ddlifsavetofjx.SelectedValue;
                Hyoa_mail.hy_yxj = "";
                Hyoa_mail.hy_yjbg = "";
                Hyoa_mail.hy_zycd = "";
                Hyoa_mail.hy_hz = "";
                Hyoa_mail.Insert();
            }
        }

        Response.Write("<script>alert('" + ls_tip + "');window.location='" + this.txturl.Value + "'</script>");
    }