Spring Boot trouble using the template engine

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Spring Boot trouble using the template engine

cesco
Hi guys!

I am quite new to thymeleaf but I am loving. I am having this issue that is bugging me a lot.
I am trying to replicate the Rich HTML email in Spring with Thymeleaf inside my Spring Boot app. I am stuck at sending a simple email, not because of sending the email, but because of the templeteEngine.process method.

If I do:

final String htmlContent = "whatever";
message.setText(htmlContent, false);
javaMailSender.send(mimeMessage);

I receive the email correctly.Although doing

final String htmlContent = this.templateEngine.process("mail/email-simple.html", ctx);
message.setText(htmlContent, true /* isHtml */);
javaMailSender.send(mimeMessage);

I get this error:

public java.lang.String com.example.controllers.MailController.sendSimpleMail(java.lang.String,java.lang.String,java.util.Locale) throws javax.mail.MessagingException

I tried these two configs

    @Autowired
    private SpringTemplateEngine templateEngine;

    @Autowired
    private TemplateEngine te;

I am not using any configurations btw, but I am pretty sure thats where the problem is.
I tought i would be done by spring boot alone. Thanks

Reply | Threaded
Open this post in threaded view
|

Re: Spring Boot trouble using the template engine

Zemi
Administrator
Hello,

Have you take a look at the companion application for the article
  https://github.com/thymeleaf/thymeleafexamples-springmail

Maybe is easier to start with a working application and modify it to suit your needs.

Please be aware that for the example to work you need to configure the files src/main/resources/configuration.properties and src/main/resources/javamail.properties

Kind Regards,
  Zemi

Reply | Threaded
Open this post in threaded view
|

Re: Spring Boot trouble using the template engine

cesco
People at SO already helped me. Spring boot come with a template handler configured with .html suffix, so all I had to do is get rid of the .html and bang. Thanks anyway