Example #1
0
 protected void btndelinfo_Click(object sender, EventArgs e)
 {
     HyoaClass.Hyoa_mail_config Hyoa_mail_config = new HyoaClass.Hyoa_mail_config();
     String[] v_uids = this.txtuids.Value.Split(',');
     for (var i = 0; i < v_uids.Length; i++)
     {
         if (v_uids[i] != "")
         {
             Hyoa_mail_config.ID = v_uids[i];
             Hyoa_mail_config.Delete();
         }
     }
     this.txtuids.Value = "";
     //DataPlay(1);
     DataPlay(System.Int32.Parse(this.curpage.Text));
 }
    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>");
        }
    }
Example #3
0
    private void DataPlay(int PageNo)
    {
        //加载外部收件账号
        string lswbjszh = "--按账号查看--";
        if (this.Request.QueryString["wbjszh"] != null)
        {
            lswbjszh = this.Request.QueryString["wbjszh"].ToString();
        }
        HyoaClass.Hyoa_mail_config Hyoa_mail_config = new HyoaClass.Hyoa_mail_config();
        DataTable dtmailconfig = Hyoa_mail_config.Getmailconfigbyuserid(this.Session["hyuid"].ToString());
        if (dtmailconfig.Rows.Count > 0)
        {
            this.ddlwbjszh.DataSource = dtmailconfig;
            this.ddlwbjszh.DataTextField = "hy_mailid";
            this.ddlwbjszh.DataValueField = "hy_mailid";
            this.ddlwbjszh.DataBind();
            this.ddlwbjszh.Items.Insert(0, new ListItem("本系统邮件", "本系统邮件"));
            this.ddlwbjszh.Items.Insert(0, new ListItem("--按账号查看--", "--按账号查看--"));

            this.ddlwbjszh.SelectedValue = lswbjszh;
        }

        //得到当前页号
        this.curpage.Text = PageNo.ToString();
        HyoaClass.Hyoa_mail Hyoa_mail = new HyoaClass.Hyoa_mail();

        DataTable dt;
        if (lswbjszh == "--按账号查看--")
            lswbjszh = "";
        if (lswbjszh == "本系统邮件")
            lswbjszh = "本系统邮件";
        dt = Hyoa_mail.Getmail_sjx(Session["hyuid"].ToString(), "收件", "收件箱", lswbjszh);

        DataTable tempTable = dt.Clone();
        DataColumn col = new DataColumn("wdyj", typeof(String)); //定义新的一列  add
        tempTable.Columns.Add(col);  //追加一列  add
        for (int i = (PageNo - 1) * System.Int32.Parse(PageSize.Text); i < PageNo * System.Int32.Parse(PageSize.Text); i++)
        {
            if (i > dt.Rows.Count - 1)
                break;

            DataRow dr = tempTable.NewRow();
            for (int j = 0; j < dt.Columns.Count; j++)
            {
                dr[dt.Columns[j].ColumnName] = dt.Rows[i][j];
            }
            //得到是否未读
            string ls_wdyj = "<font color=red>未读</font>";   //add
            if(dt.Rows[i]["hy_sccksj"].ToString()!="")
                ls_wdyj = "已读";
            dr["wdyj"] = ls_wdyj;  //将新值赋给相应的列  add
            tempTable.Rows.Add(dr);
        }

        int TotalRecord = dt.Rows.Count;
        this.sumts.Text = TotalRecord.ToString();
        this.sumts2.Text = TotalRecord.ToString();
        this.ShowTotalRecord.Text = TotalRecord.ToString();
        //计算及显示总页数
        int TotalPage;
        if (TotalRecord < System.Int32.Parse(PageSize.Text))
        {
            TotalPage = 1;
        }
        else
        {
            if (TotalRecord % System.Int32.Parse(PageSize.Text) != 0)
            {
                TotalPage = TotalRecord / System.Int32.Parse(PageSize.Text) + 1;

            }
            else
            {
                TotalPage = TotalRecord / System.Int32.Parse(PageSize.Text);

            }
        }
        this.ShowTotalPage.Text = TotalPage.ToString();
        this.rptlist.DataSource = tempTable;
        this.rptlist.DataBind();
        dt.Clear();
    }
Example #4
0
    public void sendmail(string lsjsrid, string lsbt, string lsnr, string lsid)
    {
        //lsjsrid  接收人[email protected],[email protected]
        //lsbt  主题
        //lsnr  内容
        //lsfjpath 附件路径

        HyoaClass.Hyoa_mail_config Hyoa_mail_config = new HyoaClass.Hyoa_mail_config();
        DataTable dtmailuser = Hyoa_mail_config.Getmailconfigbyuserid(this.Session["hyuid"].ToString());

        string lssendid = "";
        string lssendpwd = "";
        string lssendname = "";
        string lshost = "";
        string lsport = "";
        if (dtmailuser.Rows.Count > 0)
        {
            lssendid = dtmailuser.Rows[0]["hy_mailid"].ToString();
            lssendpwd = Decrypt(dtmailuser.Rows[0]["hy_mailpwd"].ToString());
            lssendname = this.Session["hyuname"].ToString();
            lshost = dtmailuser.Rows[0]["hy_smtpurl"].ToString();
            lsport = dtmailuser.Rows[0]["hy_smtpport"].ToString();
            //lshost = lssendid.Substring(lssendid.IndexOf("@") + 1, lssendid.Length - lssendid.IndexOf("@") - 1);   //smtp的服务器地址hy_smtpurl
        }
        else
        {
            return;
        }
        string lsml = "";
        lsml = Server.MapPath("~/");//得到虚拟根目录

        SmtpClient smtp = new SmtpClient(); //实例化一个SmtpClient
        smtp.DeliveryMethod = SmtpDeliveryMethod.Network; //将smtp的出站方式设为 Network
        smtp.EnableSsl = false;//smtp服务器是否启用SSL加密

        smtp.Host = lshost; //指定 smtp 服务器地址
        smtp.Port = System.Int32.Parse(lsport);             //指定 smtp 服务器的端口,默认是25,如果采用默认端口,可省去
        ////如果你的SMTP服务器不需要身份认证,则使用下面的方式,不过,目前基本没有不需要认证的了
        //smtp.UseDefaultCredentials = true;

        //如果需要认证,则用下面的方式
        smtp.Credentials = new NetworkCredential(lssendid, lssendpwd);
        MailMessage mm = new MailMessage(); //实例化一个邮件类
        mm.Priority = MailPriority.High; //邮件的优先级,分为 Low, Normal, High,通常用 Normal即可
        mm.From = new MailAddress(lssendid, lssendname, Encoding.GetEncoding(936));
        //收件方看到的邮件来源;
        //第一个参数是发信人邮件地址
        //第二参数是发信人显示的名称
        //第三个参数是 第二个参数所使用的编码,如果指定不正确,则对方收到后显示乱码
        //936是简体中文的codepage值
        ////注:上面的邮件来源,一定要和你登录邮箱的帐号一致,否则会认证失败
        mm.ReplyTo = new MailAddress(lssendid, lssendname, Encoding.GetEncoding(936));
        //ReplyTo 表示对方回复邮件时默认的接收地址,即:你用一个邮箱发信,但却用另一个来收信
        //上面后两个参数的意义, 同 From 的意义

        //mm.CC.Add("[email protected],[email protected],[email protected]");
        ////邮件的抄送者,支持群发,多个邮件地址之间用 半角逗号 分开

        //mm.Bcc.Add("[email protected],[email protected]");
        ////邮件的密送者,支持群发,多个邮件地址之间用 半角逗号 分开

        mm.To.Add(lsjsrid);
        //邮件的接收者,支持群发,多个地址之间用 半角逗号 分开

        mm.Subject = lsbt; //邮件标题
        mm.SubjectEncoding = Encoding.GetEncoding(936);
        // 这里非常重要,如果你的邮件标题包含中文,这里一定要指定,否则对方收到的极有可能是乱码。
        // 936是简体中文的pagecode,如果是英文标题,这句可以忽略不用
        mm.IsBodyHtml = true; //邮件正文是否是HTML格式

        mm.BodyEncoding = Encoding.GetEncoding(936);
        //邮件正文的编码, 设置不正确, 接收者会收到乱码

        mm.Body = lsnr;

        //邮件正文
        HyoaClass.Hyoa_fileatt Hyoa_fileatt = new HyoaClass.Hyoa_fileatt();
        DataTable dtfileatt = Hyoa_fileatt.GetfileattByFatherid(lsid);
        if (dtfileatt.Rows.Count > 0)
        {
            for (int jj = 0; jj < dtfileatt.Rows.Count; jj++)
            {
                if (jj == 0)
                {
                    //添加附件,第二个参数,表示附件的文件类型,可以不用指定
                    mm.Attachments.Add(new Attachment(@lsml + "\\" + dtfileatt.Rows[jj]["hy_filepath"].ToString(), System.Net.Mime.MediaTypeNames.Application.Rtf));
                }
                else
                {//可以添加多个附件
                    mm.Attachments.Add(new Attachment(@lsml + "\\" + dtfileatt.Rows[jj]["hy_filepath"].ToString()));
                }
            }
        }

        smtp.Send(mm); //发送邮件,如果不返回异常, 则大功告成了。
    }
Example #5
0
    private void DataPlay()
    {
        this.hy_ifsavebak.Items.Insert(0, "是");
        this.hy_ifsavebak.Items.Insert(1, "否");

        this.btn_submit.Visible = true; //保存

        if (this.Session["hyuid"].ToString() != "")
        {

            //根据用户ID得到信息
            this.txtuserid.Text = this.Session["hyuid"].ToString();
            this.txtusername.Text = this.Session["hyuname"].ToString();
            HyoaClass.Hyoa_mail_config Hyoa_mail_config = new HyoaClass.Hyoa_mail_config();
            DataTable dtmail_config = Hyoa_mail_config.Getmailconfigbyuserid(this.txtuserid.Text);
            if (dtmail_config.Rows.Count > 0)
            {
                this.hy_mailid.Text = dtmail_config.Rows[0]["hy_mailid"].ToString();
                this.hy_mailpwd.Text = Decrypt(dtmail_config.Rows[0]["hy_mailpwd"].ToString());
                this.hy_smtpurl.Text = dtmail_config.Rows[0]["hy_smtpurl"].ToString();
                this.hy_smtpport.Text = dtmail_config.Rows[0]["hy_smtpport"].ToString();
                this.hy_pop3url.Text = dtmail_config.Rows[0]["hy_pop3url"].ToString();
                this.hy_pop3port.Text = dtmail_config.Rows[0]["hy_pop3port"].ToString();

                if (dtmail_config.Rows[0]["hy_ifsavebak"].ToString() == "是")
                    this.hy_ifsavebak.SelectedIndex = 0;
                else
                    this.hy_ifsavebak.SelectedIndex = 1;
            }
            dtmail_config.Clear();

        }
    }
Example #6
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_config Hyoa_mail_config = new HyoaClass.Hyoa_mail_config();
        //先判断这个用户是否已经存在
        DataTable dtmail = Hyoa_mail_config.Getmailconfigbyuserid(this.txtuserid.Text);
        HyoaClass.Hyoa_global Hyoa_global = new HyoaClass.Hyoa_global();
        if (dtmail.Rows.Count > 0)
        {
            Hyoa_mail_config.hy_userid = this.txtuserid.Text;
            Hyoa_mail_config.hy_mailid = this.hy_mailid.Text;
            Hyoa_mail_config.hy_mailpwd = Encrypt(this.hy_mailpwd.Text);
            Hyoa_mail_config.hy_smtpurl=this.hy_smtpurl.Text;
            Hyoa_mail_config.hy_smtpport = this.hy_smtpport.Text;
            Hyoa_mail_config.hy_pop3url = this.hy_pop3url.Text;
            Hyoa_mail_config.hy_pop3port = this.hy_pop3port.Text;
            Hyoa_mail_config.hy_ifsavebak = this.hy_ifsavebak.Text;
            Hyoa_mail_config.Update();
        }
        else
        {
            Hyoa_mail_config.ID = Hyoa_global.GetRandom();
            Hyoa_mail_config.hy_userid = this.txtuserid.Text;
            Hyoa_mail_config.hy_mailid = this.hy_mailid.Text;
            Hyoa_mail_config.hy_mailpwd = Encrypt(this.hy_mailpwd.Text);
            Hyoa_mail_config.hy_smtpurl = this.hy_smtpurl.Text;
            Hyoa_mail_config.hy_smtpport = this.hy_smtpport.Text;
            Hyoa_mail_config.hy_pop3url = this.hy_pop3url.Text;
            Hyoa_mail_config.hy_pop3port = this.hy_pop3port.Text;
            Hyoa_mail_config.hy_ifsavebak = this.hy_ifsavebak.Text;
            Hyoa_mail_config.Insert();
        }

        //处理完成后的提示及跳转
        if (this.txtifpop.Value == "")
        {
            Response.Write("<script>alert('" + ls_tip + "');</script>");
        }
        else
        {
            Response.Write("<script>alert('" + ls_tip + "');self.close();</script>");
        }
    }
Example #7
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_config Hyoa_mail_config = new HyoaClass.Hyoa_mail_config();
        //先判断这个用户是否已经存在
        DataTable dtmail = Hyoa_mail_config.Getmailconfigbyuserid(this.txtuserid.Text);
        HyoaClass.Hyoa_global Hyoa_global = new HyoaClass.Hyoa_global();
         string lsop = "";
        if (this.Request.QueryString["op"] != null)
        {
            lsop = this.Request.QueryString["op"].ToString();   //是否弹出窗口
        }

        if (lsop == "add")
        {
            Hyoa_mail_config.ID = Hyoa_global.GetRandom();
            Hyoa_mail_config.hy_userid = this.txtuserid.Text;
            Hyoa_mail_config.hy_mailid = this.hy_mailid.Text;
            Hyoa_mail_config.hy_mailpwd = Encrypt(this.hy_mailpwd.Text);
            Hyoa_mail_config.hy_smtpurl = this.hy_smtpurl.Text;
            Hyoa_mail_config.hy_smtpport = this.hy_smtpport.Text;
            Hyoa_mail_config.hy_pop3url = this.hy_pop3url.Text;
            Hyoa_mail_config.hy_pop3port = this.hy_pop3port.Text;
            Hyoa_mail_config.hy_ifsavebak = this.hy_ifsavebak.Text;
            Hyoa_mail_config.hy_sort = System.Int32.Parse(this.hy_sort.Text);
            Hyoa_mail_config.Insert();
        }
        else
        {
            Hyoa_mail_config.ID = this.txtdocid.Value;
            Hyoa_mail_config.hy_userid = this.txtuserid.Text;
            Hyoa_mail_config.hy_mailid = this.hy_mailid.Text;
            Hyoa_mail_config.hy_mailpwd = Encrypt(this.hy_mailpwd.Text);
            Hyoa_mail_config.hy_smtpurl = this.hy_smtpurl.Text;
            Hyoa_mail_config.hy_smtpport = this.hy_smtpport.Text;
            Hyoa_mail_config.hy_pop3url = this.hy_pop3url.Text;
            Hyoa_mail_config.hy_pop3port = this.hy_pop3port.Text;
            Hyoa_mail_config.hy_ifsavebak = this.hy_ifsavebak.Text;
            Hyoa_mail_config.hy_sort = System.Int32.Parse(this.hy_sort.Text);
            Hyoa_mail_config.Update();
        }

        //处理完成后的提示及跳转
        if (this.txtifpop.Value == "")
        {
            Response.Write("<script>alert('" + ls_tip + "');window.location='/mail/list_grxx.aspx'</script>");
        }
        else
        {
            Response.Write("<script>alert('" + ls_tip + "');self.close();</script>");
        }
    }
Example #8
0
    private void DataPlay()
    {
        this.hy_ifsavebak.Items.Insert(0, "是");
        this.hy_ifsavebak.Items.Insert(1, "否");

        this.btn_submit.Visible = true; //保存

        if (this.Session["hyuid"].ToString() != "")
        {
            string lsop = "";
            if (this.Request.QueryString["op"] != null)
            {
                lsop = this.Request.QueryString["op"].ToString();   //是否弹出窗口
            }

            if (lsop == "add")
            {
                this.txtuserid.Text = this.Session["hyuid"].ToString();
                this.txtusername.Text = this.Session["hyuname"].ToString();
                this.hy_mailid.Text = "";
                this.hy_mailpwd.Text ="";
                this.hy_smtpurl.Text = "";
                this.hy_smtpport.Text = "";
                this.hy_pop3url.Text = "";
                this.hy_pop3port.Text = "";
                this.hy_ifsavebak.SelectedIndex = 0;
                this.hy_sort.Text = "";
            }
            else
            {
                //根据用户ID得到信息
                this.txtuserid.Text = this.Session["hyuid"].ToString();
                this.txtusername.Text = this.Session["hyuname"].ToString();
                string lsid = "";
                if (this.Request.QueryString["id"] != null)
                {
                    lsid = this.Request.QueryString["id"].ToString();   //是否弹出窗口
                }
                HyoaClass.Hyoa_mail_config Hyoa_mail_config = new HyoaClass.Hyoa_mail_config();
                DataTable dtmail_config = Hyoa_mail_config.Getmailconfigbyid(lsid);
                if (dtmail_config.Rows.Count > 0)
                {
                    this.txtdocid.Value = dtmail_config.Rows[0]["ID"].ToString();
                    this.hy_mailid.Text = dtmail_config.Rows[0]["hy_mailid"].ToString();
                    this.hy_mailpwd.Text = Decrypt(dtmail_config.Rows[0]["hy_mailpwd"].ToString());
                    this.hy_smtpurl.Text = dtmail_config.Rows[0]["hy_smtpurl"].ToString();
                    this.hy_smtpport.Text = dtmail_config.Rows[0]["hy_smtpport"].ToString();
                    this.hy_pop3url.Text = dtmail_config.Rows[0]["hy_pop3url"].ToString();
                    this.hy_pop3port.Text = dtmail_config.Rows[0]["hy_pop3port"].ToString();

                    if (dtmail_config.Rows[0]["hy_ifsavebak"].ToString() == "是")
                        this.hy_ifsavebak.SelectedIndex = 0;
                    else
                        this.hy_ifsavebak.SelectedIndex = 1;

                    this.hy_sort.Text = dtmail_config.Rows[0]["hy_sort"].ToString();
                }
                dtmail_config.Clear();
            }

        }
    }
Example #9
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)
        {
            for (int ii = 0; ii < dtconfig.Rows.Count; ii++)
            {

                string pop3Server = dtconfig.Rows[ii]["hy_pop3url"].ToString();// "pop.163.com";    //邮箱服务器 如:"pop.sina.com.cn";或 "pop.qq.com" 好像sina的比较快
                int pop3Port = System.Int32.Parse(dtconfig.Rows[ii]["hy_pop3port"].ToString()); //110;          //端口号码   用"110"好使。最好看一下你的邮箱服务器用的是什么端口号
                bool pop3UseSsl = false;
                string lsmailid = dtconfig.Rows[ii]["hy_mailid"].ToString();
                //string username = lsmailid.Substring(0, lsmailid.IndexOf("@"));//"ztmfang2008";        //你的邮箱用户名
                string username = lsmailid;//"ztmfang2008";        //你的邮箱用户名
                string password = Decrypt(dtconfig.Rows[ii]["hy_mailpwd"].ToString()); //"20120328";      //你的邮箱密码
                ReciveByJmail(username, password, pop3Server, pop3Port);
            }

            this.Response.Write("<script>alert('邮件接收完成!');window.opener.location.reload();window.close();</script>");
        }
        else
        {
            this.Response.Write("<script>alert('请先配置外网邮件信息!');</script>");
        }
    }
Example #10
0
    public void sendmail(string lsjsrid,string lsbt,string lsnr,string lsid)
    {
        //lsjsrid  接收人[email protected],[email protected]
        //lsbt  主题
        //lsnr  内容
        //lsfjpath 附件路径

           HyoaClass.Hyoa_mail_config Hyoa_mail_config = new HyoaClass.Hyoa_mail_config();
           DataTable dtmailuser = Hyoa_mail_config.Getmailconfigbyuserid(this.Session["hyuid"].ToString());

           string lssendid = "";
           string lssendpwd = "";
           string lssendname = "";
           string lshost = "";
           string lsport = "";

           if (dtmailuser.Rows.Count > 0)
           {
               for (int n = 0; n < dtmailuser.Rows.Count; n++)
               {
                   if (dtmailuser.Rows[n]["hy_mailid"].ToString() == this.ddlmailset.SelectedValue.ToString())
                   {
                       lssendid = dtmailuser.Rows[n]["hy_mailid"].ToString();
                       lssendpwd = Decrypt(dtmailuser.Rows[n]["hy_mailpwd"].ToString());
                       lssendname = this.Session["hyuname"].ToString();
                       lshost = dtmailuser.Rows[n]["hy_smtpurl"].ToString();
                       lsport = dtmailuser.Rows[n]["hy_smtpport"].ToString();
                   }
               }
           }
           else
           {
           return;
           }

           string lsml = "";
           lsml = Server.MapPath("~/");//得到虚拟根目录
           jmail.Message jmail = new jmail.Message();
           DateTime t = DateTime.Now;
           String Subject = lsbt;
           String body = lsnr;
           String FromEmail = lssendid;
           String ToEmail = lsjsrid;
           //Silent属性:如果设置为true,JMail不会抛出例外错误. JMail. Send( () 会根据操作结果返回true或false
           jmail.Silent = true;
           //Jmail创建的日志,前提loging属性设置为true
           jmail.Logging = true;
           //字符集,缺省为"US-ASCII"
           jmail.From = FromEmail;
           jmail.Charset="gb2312";
        jmail.ContentTransferEncoding="base64";
        jmail.Encoding="base64";
        jmail.ISOEncodeHeaders=false;

           //信件的contentype. 缺省是"text/plain") : 字符串如果你以HTML格式发送邮件, 改为"text/html"即可。
           //jmail.ContentType = "text/html";
           //添加收件人
           string[] lvToEmail;
           lvToEmail = ToEmail.Split(',');
           for (int jj = 0; jj < lvToEmail.Length; jj++)
           {
           jmail.AddRecipient(lvToEmail[jj], "", "");
           }

           //jmail.AddRecipient(ToEmail, "", "");
           //jmail.AddRecipient(ToEmail2, "", "");
           //jmail.From = FromEmail;
           //发件人邮件用户名
           //jmail.MailServerUserName = lssendid.Substring(0,lssendid.IndexOf("@"));
           jmail.MailServerUserName = lssendid;
           //发件人邮件密码
           jmail.MailServerPassWord = lssendpwd;
           //设置邮件标题
           jmail.Subject = Subject;
           //邮件内容
           jmail.HTMLBody = body;
           //邮件添加附件,(多附件的话,可以再加一条Jmail.AddAttachment( "c:test.jpg",true,null);)就可以搞定了。[注]:加了附件,讲把上面的 Jmail.ContentType="text/html";删掉。否则会在邮件里出现乱码。
           //jmail.AddAttachment(@"D:\bbb.rar", true, "htm");
           //jmail.AddAttachment(@"D:\bbb.txt", true, "htm");
           //邮件附件
           HyoaClass.Hyoa_fileatt Hyoa_fileatt = new HyoaClass.Hyoa_fileatt();
           DataTable dtfileatt = Hyoa_fileatt.GetfileattByFatherid(lsid);
           if (dtfileatt.Rows.Count > 0)
           {
           for (int jj = 0; jj < dtfileatt.Rows.Count; jj++)
           {
               jmail.AddAttachment(@lsml + "\\" + dtfileatt.Rows[jj]["hy_filepath"].ToString(), true, "htm");
           }
           }
           //Jmail发送的方法
           jmail.Send(lshost, false);
           jmail.Close();
    }
Example #11
0
    private void DataPlay()
    {
        HyoaClass.Hyoa_mail_config Hyoa_mail_config = new HyoaClass.Hyoa_mail_config ();
        DataTable dtmailcon = Hyoa_mail_config.Getmailconfigbyuserid(Session["hyuid"].ToString());
        for(int ii=0;ii<dtmailcon.Rows.Count;ii++)
        {
             this.ddlmailset.Items.Insert(ii,dtmailcon.Rows[ii]["hy_mailid"].ToString());
        }

        //新文档
        if (this.txtop.Value == "add")
        {
            HyoaClass.Hyoa_global Hyoa_global = new HyoaClass.Hyoa_global();
            this.txtdocid.Value = Hyoa_global.GetRandom();
            this.lblhy_fsrid.Text = Session["hyuid"].ToString();
            this.lblhy_fsrname.Text = Session["hyuname"].ToString();
            this.lblhy_datetime.Text = System.DateTime.Now.ToString();
            //如果是回复
            if (this.Request.QueryString["fhid"] != null)
            {
                HyoaClass.Hyoa_mail Hyoa_mail = new HyoaClass.Hyoa_mail();
                DataTable dt = Hyoa_mail.Getmail(this.Request.QueryString["fhid"].ToString());
                if (dt.Rows.Count > 0)
                {
                    if (dt.Rows[0]["hy_wbjsrid"].ToString() != "")
                    {
                        //this.txthy_jsrid.Text = dt.Rows[0]["hy_fsrid"].ToString();
                        this.txthy_wbjsrid.Text = dt.Rows[0]["hy_fsrid"].ToString();
                        //this.txthy_jsrid.Text = dt.Rows[0]["txthy_wbjsrid"].ToString();
                        //this.txthy_jsrname.Value = dt.Rows[0]["hy_fsrname"].ToString();
                        this.txthy_title.Text = "回复:" + dt.Rows[0]["hy_title"].ToString();
                    }
                    else
                    {
                        this.txthy_jsrid.Text = dt.Rows[0]["hy_fsrid"].ToString();
                        //this.txthy_wbjsrid.Text = dt.Rows[0]["hy_fsrid"].ToString();
                        this.txthy_jsrname.Value = dt.Rows[0]["hy_fsrname"].ToString();
                        this.txthy_title.Text = "回复:" + dt.Rows[0]["hy_title"].ToString();
                    }
                }
            }
             //如果是从在线人员中过来的
            if (this.Request.QueryString["recuserid"] != null)
            {
                HyoaClass.Hyoa_user Hyoa_user = new HyoaClass.Hyoa_user();
                DataTable dtuser = Hyoa_user.Getuserallinfo(this.Request.QueryString["recuserid"].ToString());
                if (dtuser.Rows.Count > 0)
                {
                    this.txthy_jsrid.Text = this.Request.QueryString["recuserid"].ToString();
                    this.txthy_jsrname.Value = dtuser.Rows[0]["hy_username"].ToString();
                }
            }
            //如果是转发
            if (this.Request.QueryString["zfid"] != null)
            {
                HyoaClass.Hyoa_mail Hyoa_mail = new HyoaClass.Hyoa_mail();
                DataTable dt = Hyoa_mail.Getmail(this.Request.QueryString["zfid"].ToString());
                if (dt.Rows.Count > 0)
                {
                    this.txthy_title.Text = "转发:" + dt.Rows[0]["hy_title"].ToString();
                    this.hy_content1.Value = dt.Rows[0]["hy_body"].ToString();
                    this.txtdocid.Value = dt.Rows[0]["docid"].ToString();

                    //附件
                    HyoaClass.Hyoa_fileatt Hyoa_fileatt = new HyoaClass.Hyoa_fileatt();
                    DataTable dt_fileatt = Hyoa_fileatt.GetfileattByFatherid(dt.Rows[0]["DOCID"].ToString());
                    if (dt_fileatt.Rows.Count > 0)
                    {
                        string ls_temp = "";
                        for (var i = 0; i < dt_fileatt.Rows.Count; i++)
                        {
                            ls_temp += (i + 1).ToString() + "、<a href='/" + dt_fileatt.Rows[i]["hy_filepath"].ToString() + "' target='_blank'>" + dt_fileatt.Rows[i]["hy_filename"].ToString() + "</a><br />";
                        }
                        this.lblhy_field2.Text = ls_temp;

                    }
                }
                this.uploadhy_field2.Visible = false;
            }
        }
        else
        {
            if (this.Request.QueryString["id"] != null)
            {
                this.txtid.Value = this.Request.QueryString["id"].ToString();
            }
            HyoaClass.Hyoa_mail Hyoa_mail = new HyoaClass.Hyoa_mail();
            DataTable dt = Hyoa_mail.Getmail(this.txtid.Value);
            if (dt.Rows.Count > 0)
            {
                this.txtdocid.Value = dt.Rows[0]["DOCID"].ToString();
                this.txtid.Value = dt.Rows[0]["ID"].ToString();

                this.lblhy_fsrid.Text = dt.Rows[0]["hy_fsrid"].ToString();
                this.lblhy_fsrname.Text = dt.Rows[0]["hy_fsrname"].ToString();
                this.lblhy_datetime.Text = dt.Rows[0]["hy_datetime"].ToString();
                this.txthy_jsrname.Value = dt.Rows[0]["hy_jsrname"].ToString();
                this.txthy_jsrid.Text = dt.Rows[0]["hy_jsrid"].ToString();
                this.txthy_wbjsrid.Text = dt.Rows[0]["hy_wbjsrid"].ToString();
                this.txthy_title.Text = dt.Rows[0]["hy_title"].ToString();

                //附件
                HyoaClass.Hyoa_fileatt Hyoa_fileatt = new HyoaClass.Hyoa_fileatt();
                DataTable dt_fileatt = Hyoa_fileatt.GetfileattByFatherid(this.txtdocid.Value);
                if (dt_fileatt.Rows.Count > 0)
                {
                    string ls_temp = "";
                    for (var i = 0; i < dt_fileatt.Rows.Count; i++)
                    {
                        ls_temp += (i + 1).ToString() + "、<a href='/" + dt_fileatt.Rows[i]["hy_filepath"].ToString() + "' target='_blank'>" + dt_fileatt.Rows[i]["hy_filename"].ToString() + "</a><br />";
                    }
                    this.lblhy_field2.Text = ls_temp;
                }

                this.hy_content1.Value = dt.Rows[0]["hy_body"].ToString();
                this.ddlifsavetofjx.SelectedValue = dt.Rows[0]["hy_ifsavetofjx"].ToString();

            }

            //20120210 start
            if (dt.Rows[0]["hy_type"].ToString() == "发件" & dt.Rows[0]["hy_foldername"].ToString() == "发件箱")
            {

                string text = "<TR height='30'><TD width='20%' align='center' class='Tdcellleft'>序号</TD><TD width='40%' align='center' class='Tdcellleft'>姓名</TD><TD width='40%' align='center' class='Tdcellleft'>回执时间</TD></TR>";
                HyoaClass.DAO db = new HyoaClass.DAO();
                string sql = "";
                sql = "select * from hyt_mail where DOCID='" + this.txtdocid.Value + "' and hy_type ='收件' and hy_sccksj <> '' order by hy_sccksj asc";
                DataTable dt2 = db.GetDataTable(sql);
                if (dt2.Rows.Count > 0)
                {
                    for (var i = 0; i < dt2.Rows.Count; i++)
                    {
                        text = text + "<TR height='30'><TD width='20%' align='center' class='Tdcellright'>" + (i+1).ToString() + "</TD>";
                        text = text + "<TD width='40%' align='center' class='Tdcellright'>" + dt2.Rows[i]["hy_jsrname"].ToString() + "</TD>";
                        text = text + "<TD width='40%' align='center' class='Tdcellright'>" + dt2.Rows[i]["hy_sccksj"].ToString() + "</TD></TR>";
                    }
                }
                this.hzlb.Text = text;
            }
            //20120210 end
         }
    }