请问各位我用jmail的写收邮件的时候Subject里的东西都是乱码,特别是在收中文的时候,英文的话还算正常,再一个就是如果转发的邮件的话就也会出先这个情况并且附件件name会变成我声明的jmail的名称不是原来附件的名称!

解决方案 »

  1.   

    jmail有个设置字符集的属性,设置为gb2312或者utf-8.附件的中文名称可以先编码再解码
      

  2.   

    private void JMailReceive()
        {
            jmail.Message Msg = new jmail.Message();
            jmail.POP3 jpop = new jmail.POP3();
            jmail.Attachments atts;
            jmail.Attachment att;
                   //username为用户名,该方法通过用户名获取该用户的pop设置,即用户的POP用户名,密码,POP服务器地址以及端口号这四个参数,这四个参数是连接POP服务器的必用参数.
            //连接POP服务器
            jpop.Connect(Session["empid"].ToString(), "19841023pj", "pop.163.com", 110);
            //如果服务器上有邮件
            if (jpop.Count >= 1)
            {
                for (int i = 1; i <= jpop.Count; i++)
                {                Msg = jpop.Messages[i];
                    atts = Msg.Attachments;
                    Msg.Charset = "gb2312";
                    Msg.ContentTransferEncoding = "base64";
                    Msg.Encoding = "base64";
                    Msg.ISOEncodeHeaders = false;
                    //取数据库中邮件信息中的最大发送时间,即最近接收到的一封邮件的时间                SqlDataReader MailReader = SqlHelper.ExecuteReader(connectionstring(), CommandType.Text, "select max(MailSendDate) from mail");
                    //DataTable data = dbase.GetDataTable("select max(MailSendDate) as MailSenderDate from TabMailList where MailTypeFlag='1'");                //对服务器上的邮件的发送时间和数据库最近一封邮件的时间进行比较,如果大那么证明该邮件还未被收取,是一封新邮件,这样避免重复收取邮件入库
                    //if ((MailReader.GetValue(0).ToString()==null) || (Msg.Date > Convert.ToDateTime(MailReader.GetValue(0).ToString())))
                    //{
                    //将这封新邮件的信息保存到数据库
                    this.SaveExtMail(Msg, Session["empid"].ToString(), Msg.Date, jpop.GetMessageUID(i));                //获取附件上传到服务器并且将信息存入数据库
                    if (atts.Count >= 1)
                    {
                        for (int k = 0; k < atts.Count; k++)
                        {                        att = atts[k];//获得附件                        string attname = att.Name;
                            try
                            {                            Random TempNameInt = new Random();
                                string NewMailDirName = TempNameInt.Next(100000000).ToString();
                                Directory.CreateDirectory(System.Web.HttpContext.Current.Server.MapPath(".") + "\\AttachFiles\\" + Session["empid"].ToString() + "\\" + NewMailDirName);                            string mailPath = "\\AttachFiles\\" + Session["empid"].ToString() + "\\" + NewMailDirName + "\\" + attname;                            att.SaveToFile(System.Web.HttpContext.Current.Server.MapPath(".") + mailPath);                            //获取该封邮件在数据库的ID,以便和附件信息相对应,取邮件表中的最大ID即可 
                                int mailID = this.GetMailID();
                                //将附件信息存入数据库
                                this.AttExtSend(mailID, attname, att.Size, mailPath, Msg.From);
                            }
                            catch (Exception ex)
                            {
                                throw new Exception(ex.Message);
                            }                    }
                    }
                }
            }
            //}        //删除服务器上的邮件
            //jpop.DeleteMessages();
            //断开连接
            jpop.Disconnect();
        }
    我的代码是这样写的!