Cyrillic text in mail problem
584397Nov 15 2010 — edited Jul 26 2011Hi, I want to send mail with cyrillic text in the subject and in the body. I try to encode the text with
Message msg = new MimeMessage(mailSession);
msg.setSubject(MimeUtility.encodeText("Регистрация ", "UTF-8", "B"); and
MimeBodyPart messagePart = new MimeBodyPart();
messagePart.setText("Успешна регистрация. "
+ "Вече може да влизате в системата със създадените от вас "
+ "потребителско име и парола.", "UTF-8");
but I received only unreadable characters.
here is my whole code:
// -- Create a new message --
Message msg = new MimeMessage(mailSession);
// -- Set the FROM and TO fields --
msg.setFrom(new InternetAddress(SENDER));
msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(this.getEmail(), false));
try {
msg.setSubject(MimeUtility.encodeText("Регистрация ilovesofia.bg", "UTF-8", "B"));
} catch (UnsupportedEncodingException ex) {
Logger.getLogger(Email.class.getName()).log(Level.SEVERE, null, ex);
}
MimeMultipart multipart = new MimeMultipart();
MimeBodyPart messagePart = new MimeBodyPart();
multipart.addBodyPart(messagePart); // adding message part
//Setting the Email Body Encoding
messagePart.setText("Успешна регистрация. "
+ "Вече може да влизате в системата със създадените от вас "
+ "потребителско име и парола.", "UTF-8");
msg.setContent(multipart);
What is the right way to encode non US-ASCII text in a Message ?