Don't upcast your MimeMessage
to Message
:
MimeMessage simpleMessage = new MimeMessage(mailSession);
Then, when you want to set the message body, either call
simpleMessage.setText(text, "utf-8", "html");
or call
simpleMessage.setContent(text, "text/html; charset=utf-8");
If you'd rather use a charset other than utf-8
, substitute it in the appropriate place.
JavaMail has an extra, useless layer of abstraction that often leaves you holding classes like Multipart
, Message
, and Address
, which all have much less functionality than the real subclasses (MimeMultipart
, MimeMessage
, and InternetAddress
) that are actually getting constructed...
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…