Reputation: 490
I have a web application which has been build only using java-servlets. No spring is used. The front-end is developed using HTML and Javascript. I want to send email from the application. I have the HTML files for the emails. But there are two or three parameters that should be changed in the HTML using variables. Is there any best way to accomplish this without using Spring
I have seen this piece of code if you use Spring
MimeMessagePreparator preparator = new MimeMessagePreparator() {
public void prepare(MimeMessage mimeMessage) throws Exception {
MimeMessageHelper message = new MimeMessageHelper(mimeMessage,true,"UTF-8");
message.setTo(to);
message.setFrom(from);
message.setSubject(subject);
String text = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, template, model);
message.setText(text, true);
}
};
mailSender.send(preparator);
org.springframework.mail.javamail.MimeMessagePreparator
String org.springframework.ui.velocity.VelocityEngineUtils.mergeTemplateIntoString(VelocityEngine velocityEngine, String templateLocation, Map model) throws VelocityException
Upvotes: 0
Views: 1450
Reputation: 11234
HTML template is the matter with Velocity, not related to Spring. Spring helps to simplify sending Email coding, but if you are using HTML template for Email, it should be template framework, like Velocity, FreeMark
Upvotes: 1
Reputation: 279960
One solution is to use a templating library like Thymeleaf.
Thymeleaf allows you to write HTML in which you provide Thymeleaf specific attributes and placeholders. When it processes the HTML, Thymeleaf renders the HTML by giving a value to those placeholders and generating the correct HTML.
Upvotes: 1