2010-01-17 3 views
4

Java Mail API에 문제가 있습니다.Java 메일 charset ISO-8859-2가 작동하지 않습니다.

메일을 성공적으로 보낼 수 있지만 일부 특수 문자 (체코, 슬로바키아어 등의 ISO-8859-2 언어)는 메일에 표시되지 않습니다. IDE 출력에서도 손상됩니다.

내가 뭘 잘못하고 있니?

Message msg = new MimeMessage(session); 
msg.setContent(message, "text/plain; charset=iso-8859-2") 
+0

commons-email을 사용하지 않는 이유는 무엇입니까? – Bozho

답변

2

멀티 파트를 사용하여 해결책을 찾았습니다.

MimeMessage msg = new MimeMessage(session); 
msg.setFrom(new InternetAddress(from)); 
MimeMultipart multipart = new MimeMultipart(); 
msg.setRecipient(Message.RecipientType.TO, new InternetAddress(recipient)); 
MimeBodyPart tmpBp = new MimeBodyPart(); 
tmpBp.setContent(message,"text/plain; charset=utf-8"); 
multipart.addBodyPart(tmpBp); 
msg.setContent(multipart); 
Transport.send(msg); 
0

UTF-8을 charset으로 사용하고 IDE 콘솔이 매우 동일한 charset을 사용하도록 구성하십시오. 나는 당신이 그것에 대해 말하지 않았다 당신이 사용중인 IDE 모르겠지만, Eclipse를한다면, 당신은 창으로>환경 설정>일반>작업 영역>텍스트를 변경할 수 있습니다 파일 인코딩>기타>UTF-8.

그래도 문제가 해결되지 않으면 문제가 다른 곳에 있습니다. 어쩌면 잘못된 인코딩을 사용하여 파일에서 메시지를 읽는 것일 수 있습니다. 이를 위해 InputStreamReader을 사용해야하는데,이 경우 두 번째 생성자 인수로 charset을 사용합니다.

+0

나는 UTF-8을 시도했다 이상한 일은 수동으로 println (System.out.println ("특수 문자를 사용하는 일부 텍스트"))을 수동으로 설정할 때 IDE (NetBeans)에서 작동한다는 것입니다. 전송 된 메시지의 IDE로/출력이 손상되었습니다 :/ – miso

0

당신은 setContent

/** 
    * Convenience method that sets the given String as this part's 
    * content, with a MIME type of "text/plain" and the specified 
    * charset. The given Unicode string will be charset-encoded 
    * using the specified charset. The charset is also used to set 
    * the "charset" parameter. 
    * 
    * @param text the text content to set 
    * @param charset the charset to use for the text 
    * @exception MessagingException if an error occurs 
    */ 
    public void setText(String text, String charset) 
      throws MessagingException { 
+0

charset = "text/html; charset = utf-8"일 때 작동하지 않습니다. – Ajay

2

msg.setContent 대신 클래스 MimeMessage에서 setText 방법을 사용해야합니다 (메시지, "텍스트/일반; 문자셋 = UTF-8"); 여기에 코드입니다

당신이 제공 한 문자 세트 대신에?