A
A
Andrey Unger2013-12-23 21:49:55
Java
Andrey Unger, 2013-12-23 21:49:55

How to deal with the message encoding in JavaMail?

I can't figure out the encoding in the subject line.
I do it like this:

message.setSubject("Тема сообщения", "utf-8");
message.setContent("Текст сообщения","text/plain;charset=utf-8");
message.setHeader("Content-Type", "text/plain; charset=utf-8");
Date timeStamp = new Date();
message.setSentDate(timeStamp);
Transport.send(message);

The text comes in the correct encoding, but the subject does not. In the source code of the letter, it is in base64 - some kind of abracadabra when decoding.
JavaMail using from glassfish

Answer the question

In order to leave comments, you need to log in

3 answer(s)
F
FanKiLL, 2013-12-24
@FanKiLL

Try to remove

message.setHeader("Content-Type", "text/plain; charset=utf-8");

D
DieMust, 2013-12-24
@DieMust

try adding something like this

message.setHeader("Content-Transfer-Encoding", "base64");

R
Ruslan Lopatin, 2013-12-24
@lorus

Are you sure the source code is in UTF-8? Otherwise, you can write a string in cp1251, and JavaMail says that it is UTF-8. Whether it is not enough - check just in case. And then the implementation of MimeMessage.setSubject () is very simple. It's hardly because of her.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question