Thanks Rod,
I had done just that and it all works now. Thanks for the suggestion. For the benefit of others, here is the actual code:
sw is a StringWriter.
Code:
try {
mailSender.send(new MimeMessagePreparator() {
public void prepare(MimeMessage mimeMessage) throws MessagingException {
MimeMessageHelper message = new MimeMessageHelper(mimeMessage, true, "UTF-8");
message.setFrom(from);
if (!to.equals("") && StringUtils.commaDelimitedListToStringArray(to).length > 0)
message.setTo(StringUtils.commaDelimitedListToStringArray(to));
if (!cc.equals("") && StringUtils.commaDelimitedListToStringArray(cc).length > 0)
message.setCc(StringUtils.commaDelimitedListToStringArray(cc));
if (!bcc.equals("") && StringUtils.commaDelimitedListToStringArray(bcc).length > 0)
message.setBcc(StringUtils.commaDelimitedListToStringArray(bcc));
message.setSubject(subject + " - " + request.getServerName()+" ("+request.getRemoteAddr()+")");
String mailBody = sw.toString();
try {
mailBody = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, "/WEB-INF/velocity/en_EN/errorview.vm", "UTF-8", myModel);
} catch (VelocityException ve) {
logger.error("Exception in VelocityEngineUtils - mail not sent");
}
message.setText(mailBody, true);
logger.error("Sent exception email to: "+to+" (cc: "+cc+")");
}
});
} catch (Exception e) {
logger.error("Exception occured sending exception email - " + e.getMessage());
}
return new ModelAndView("errorview", "model", myModel);