String subject = m.getSubject();
        m.setContent(subject, "text/html; charset=gb2312");
        System.out.println(subject);

解决方案 »

  1.   

    subject = new String(subject.getBytes("ISO8859_1"));
      

  2.   

    看看这篇文章,刚找到的。
     
                  论JAVAMAIL的中文解决方案 
                     2001-03-20 10:17        --------------------------------------------------------------------------------
     
          
     
        javamail在jsp中调用 目前JAVAMAIL支持的汉字编码方式有 gb2312,GBK,utf-8,iso-88
    59-1,us-assic共5种,解码的函数在类MimeUtility中,叫做decodeText,如果采用前三种方式
    ,直接得到中文。后两种还需要自己再编个小函数解码,才能显示中文, javamail里的getS
    ubject()会自动解码,但不会区分是否需要getstr,所以不直接使用getSubject(),而应该使用
    getHeader() 函数如下:(附例子,是经过修改的getSubject) 
      public static String getstr(String str) { 
        try { 
            String temp_p=str; 
            byte[] temp_t=temp_p.getBytes(“ISO8859-1“); 
            String temp=new String(temp_t); 
            return temp; 
        } catch(Exception e) { 
            return ““; 
        } 
    } 例子: 
    public String getsubject(message m) throws Exception { 
        boolean bgetstr; String temps; 
        String[] ta1=m.getHeader(“Subject“);
        String _subject; 
        if (ta1!=null) 
            _subject=ta1[0]; 
        else 
            _subject=““; 
        if (_subject.indexOf(“=?gb2312“)!=-1 || _subject.indexOf(“=?GBK“)!=-1 ||
      _subject.indexOf(“=?utf-8“)!=-1) 
            bgetstr=false; 
        else bgetstr=true; 
        try{ 
            temps=MimeUtility.decodeText(_subject); 
        } catch(UnsupportedEncodingException E) {
            return _subject;
        } if (temps.length()==0) { 
            temps=“(无主题)“; 
            bgetstr=false; 
        } if (bgetstr==false) 
            return temps; 
        else 
            return getstr(temps); 
    }