I'm sending an email and I'm receiving it correctly but the encoding of the subject is not correct. I'm sending "invitación" but I'm receiving "invitaci?n". The content of the message is OK.
The content of the message is coming from a transformation of a Velocity Template while the subject is set in a String variable.
I've googled around and I've seen that some people says that MimeUtility.encodeText() could solve the problem, but I have had no success with it.
How can I solve the problem? This is the code I have so far.
String subject = "Invitación";
String msgBody = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, "/vmTemplates/template.vm", "UTF-8", model);
Properties props = new Properties();
Session session = Session.getDefaultInstance(props, null);
try {
String encodingOptions = "text/html; charset=UTF-8";
Message msg = new MimeMessage(session);
msg.setHeader("Content-Type", encodingOptions);
msg.setFrom(new javax.mail.internet.InternetAddress(emailFrom));
msg.addRecipient(Message.RecipientType.TO, new InternetAddress(emailTo));
msg.setSubject(subject);
msg.setContent(msgBody, encodingOptions);
Transport.send(msg);
} catch (AddressException e) {
...
} catch (MessagingException e) {
...
}
Thanks