MimeBodyPart.setFileName(filename);
直接使用有可能中文乱码可以使用如下的方法
-
MimeBodyPart.setFileName(MimeUtility.encodeWord(fileName));
使用这个可以实现中文的显示(客户端和服务器端都可以)
可以查看RFC2047文件了解encodeWord详情。下面部分原文信息……
Generally, an "encoded-word" is a sequence of printable ASCII
characters that begins with "=?", ends with "?=", and has two "?"s in
between. It specifies a character set and an encoding method, and
also includes the original text encoded as graphic ASCII characters,
according to the rules for that encoding method.
A mail composer that implements this specification will provide a
means of inputting non-ASCII text in header fields, but will
translate these fields (or appropriate portions of these fields) into
encoded-words before inserting them into the message header.
-
MimeBodyPart.setFileName(new String(fileName.getBytes(), "ISO-8859-1"));
使用这个可以,客户端可以显示,服务端显示异常。(“复制”到服务器端显示为“澶嶅埗”)。