Where can I find a detailed code example of sending non-ASCII messages (Japanese in my case)?

John Zukowski

You need to be sure to set the character set when you set the content. The following example demonstrates. The message content is the numbers from 1-10.


import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;

public class SendJIS {
  public static void main (String args[]) throws Exception {
    String host = args[0];
    String from = args[1];
    String to = args[2];

    // Get system properties
    Properties props = System.getProperties();

    // Setup mail server
    props.put("mail.smtp.host", host);

    // Get session
    Session session = Session.getInstance(props, null);

    // Define message
    MimeMessage message = new MimeMessage(session);
    message.setFrom(new InternetAddress(from));
    message.addRecipient(Message.RecipientType.TO, 
      new InternetAddress(to));
    message.setSubject("Hello JIS JavaMail");

    String jisText = 
      "u4E00u4E8Cu4E09u56DBu4E94u516Du4E03u516Bu4E5Du5341";

    message.setContent(jisText, "text/plain; charset=JIS");

    // Send message
    Transport.send(message);
  }
}
For some reason this only displays 1-6 okay as far as the content. I don't know why 7-10 is messed up. As I don't use Japanese that much, it could be my configuration.
0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact