呼叫setCharset此方法,設定編碼方式為UTF-8
public void setCharset(java.lang.String newCharset)http://jakarta.apache.org/commons/email/api-release/org/apache/commons/mail/Email.html#setCharset(java.lang.String)
[常見問題2]sent出去的mail的中文內文便成亂碼
呼叫setContent此方法,第一個參數給予訊息內容,第二個參數給予conent type,例如text/plain;charset=UTF-8
public void setContent(java.lang.Object aObject,http://jakarta.apache.org/commons/email/api-release/org/apache/commons/mail/Email.html#setContent(java.lang.Object,%20java.lang.String)
java.lang.String aContentType)
[常見問題3]sent出去的附件中文檔名變成亂碼
在EmailAttachment的物件中的setName方法中,使用MimeUtility的encodeText方法
attachment.setName(MimeUtility.encodeText("中文訊息", "UTF-8", null));
http://java.sun.com/products/javamail/javadocs/javax/mail/internet/MimeUtility.html
No comments:
Post a Comment