Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Cyrillic text in mail problem

584397Nov 15 2010 — edited Jul 26 2011
Hi, 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 ?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 23 2011
Added on Nov 15 2010
18 comments
1,583 views