JavaMail的Subject乱码问题

在emial.setSubject("SmartDrive Mismatch Records Report");

 

之前如果没有设置System.setProperty("mail.mime.charset","UTF-8");

 

在Linux的系统上可能会出现乱码如下

 

=?ANSI_X3.4-1968?Q?SmartDrive_Mismatch_Records_Report_?=

 

这里小小的记录一下!

 

 

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");

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值