我正在使用JavaMail从Grails应用程序发送邮件。这是邮件服务的一部分:
try{
Session session = Session.getDefaultInstance(props, null);
MimeMessage message = new MimeMessage(session);
InternetAddress to_address = new InternetAddress(to);
InternetAddress cc_address = new InternetAddress(cc);
MimeMessageHelper helper = new MimeMessageHelper(message, true, "UTF-8");
helper.setFrom(new InternetAddress(from));
helper.setTo(to_address);
helper.setCc(cc_address);
helper.setSubject(msgSubject);
helper.setText(msgText);
transport = session.getTransport("smtp");
transport.connect();
transport.sendMessage(message, message.getAllRecipients());
} finally {
if (transport != null) try { transport.close(); } catch (MessagingException logOrIgnore) {}
}
}
在控制器中,我设置了邮件所需的一切,并将其传递给邮件服务。例如:
String msgText = "Poštovani, " + "\n\n" + requestInstance.description
我遇到像š,đ,č,ć,ž等特殊角色的问题。但是只能在我直接在控制器中设置的字符串中,例如上面的例子中的 Poštovani 。我得到 Po tovani 。如果 requestInstance.description (域类实例)中存在任何这些特殊字符,则会对其进行核心编码。这里发生了什么以及如何解决它?