首先分享一段关于JAVA MAIL的代码,
http://blog.csdn.net/aptweasel/archive/2007/03/09/1524872.aspx
以上是我收发邮件的代码,大家可以收下来自己测试,
在我的这个BLOG里还有其它相关代码,有兴趣的可以看一下,通过mail.163.com接收邮件,你们可以看出来,当你们发的邮件是GB2312,一般汉字都能正确写出来,如果你们客户端发邮件(如outlook,foxmail,可以自己设定字符集类型),字符集可能为UTF-8,GBK,这里你收到的文件就乱七八糟了,令我惊呀的是,在163里不会出现乱码,而我的客户端已经面目全非了。提示,(1)一般邮件都经过64位加密,在上面的URL里,提供了解密方法,可以直接使用,但只能解GB2312,其它的方法我也没有找到,才在网上求助,希望得到高人指点。
(2),字符集是由发送方决定的。
   我已经解决gbk,和gb2312,其实他们的编码基本一样,GBK是GB2312的扩展集,substring() 一下,去除乱码,得到的就得到结果了。
而UTF—8用了双字节编码,不一样了。怎么样才能得到它的结果
为了方便,我先写一个小程序。大家帮测试,public class Tools {
/*
 * 字符转换 */
public static String convertCode(String s) {
try {
//byte[] b = s.getBytes("ISO-8859-1");
//byte[] b = s.getBytes("UTF-8");
s = new String(b, "GBK");
} catch (IOException e) {
e.printStackTrace();
return "Exception";
}
return s;
}
/*
 * 64位解密算法
 */
public static String base64Decoder(String s) throws Exception {
sun.misc.BASE64Decoder decoder = new sun.misc.BASE64Decoder();
byte[] b = decoder.decodeBuffer(s);
return (new String(b));
}
public static void main(String args[]) {
String str = "";//以下字符串全是汉字“测试”
//str="=?gb2312?B?suLK1A==?=";
//str="=?utf-8?B?wqDmtYvor5U=?=";
//str="=?GBK?B?suLK1A==?=";
str="wqDmtYvor5U=";
// String str="suLK1LLiytQ"; try {
//str = convertCode(str);
System.out.println("st:" + str);
str = base64Decoder(str);
System.out.println("st:" + str);
} catch (Exception e) {
e.printStackTrace();
}

}
}