You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@ConfigurationpublicclassEmailServiceConfiguration {
@AutowiredApplicationContextapplicationContext;
// also see ConfigurableJavaMailSenderConfiguration@AutowiredJavaMailSenderjavaMailSender;
@BeanpublicEmailTemplateRendererServiceemailTemplateRenderService() {
returnnewEmailTemplateRendererService(factory);
}
@BeanpublicEmailSenderServiceemailSenderService() {
TemplateEngineFactoryfactory = newDefaultTemplateEngineFactory(applicationContext);
returnnewEmailTemplateRendererService(factory);
}
}
publicvoidsendmail() {
DefaultEmailModelmodel = newDefaultEmailModel();
model.setFrom("foo@bar.com", "Foobar");
model.addTo("far@boo.com", "Farboo");
model.setSubject("Let's get things started");
//create a simple HTML representation from plain textStringtext = "Make sure to check out http://www.github.com";
Stringhtml = emailTemplateRendererService.textToHtml(text);
model.setText(text);
model.setHtml(html);
emailService.sendMail(model);
// ...or render a Thymeleaf template into HTML and automatically// provide a text only fallback versionMap<String, Object> renderModel = newHashMap<>();
renderModel.put("message", "Check out http://www.github.com");
html = emailTemplateRendererService.render("someTemplate", emailModel, renderModel, Locale.ENGLISH);
text = emailTemplateRendererService.htmlToText(html);
model.setText(text);
model.setHtml(html);
emailService.sendMail(model);
}
About
Library for creating and sending HTML email with Spring. Contains functionality to transform text to html, as well as html to text.