//creates the mail message preparator from JobDataMap set in MailingServiceImpl
MimeMessagePreparator preparator = new MimeMessagePreparator() {
public void prepare(MimeMessage mimeMessage) throws Exception {
VelocityEngine velocityEngine = MailingContext.getVelocityEngine();
MimeMessageHelper message = new MimeMessageHelper(mimeMessage);
MailMessage mailMessage = (MailMessage) dataMap.get("message");
message.setFrom(mailMessage.getMsgFrom());
message.setTo(mailMessage.getMsgTo());
if (!StringUtil.isEmpty(mailMessage.getMsgBcc()))
message.setBcc(mailMessage.getMsgBcc());
if (!StringUtil.isEmpty(mailMessage.getMsgCc()))
message.setCc(mailMessage.getMsgCc());
message.setSubject(mailMessage.getSubject());
String text = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, mailMessage.getTemplate(), mailMessage.getDataMap());
message.setText(text, true);
_log.info("Sending email to ["+mailMessage.getMsgTo()+"] with subject ["+mailMessage.getSubject()+"].");
}
};
//send the mail message...
mailSender.send(preparator);
}