忽略操作系统影响,使用JavaMail发信时,会发现subject中有会有乱码。需要使用系统设置属性为你需要的编码格式。

 

 

You using the JavaMail API (this is the case if you use JBoss Application Server) and you send mails with special characters like German umlauts ä,ü,ö or something else. The JavaMail Api checks the system property “file.encoding” and if set the property “mail.mime.charset”. If your program runs on a linux server like suse 10, the default charset is ANSI_X3.4-1968. In Mozilla Thunderbird you get rubbish in the subject line

=?ANSI_X3.4-1968?Q?Testmail_-_Best=3Ftigung_Ihrer_eMail-Adresse?=

To get a clean subject like “Testmail – Bestätigung Ihrer eMail Adresse”, you must use the charset Cp1252.
Just put this command in your java code:

System.setProperty("mail.mime.charset","Cp1252");

System.setProperty("mail.mime.charset","UTF-8");
 

Important for JBoss: You have to restart JBoss.