0

I'm using thymeleaf and spring boot to get an email template to work. Using a spring-boot-starter-thymelelaf library. implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'

A portion of the template (which is not working too) looks like this.

<p class="highlight-status" style="margin: 0; margin-bottom: 15px; font-family: 'Montserrat', sans-serif; text-decoration: none; color: #323232; font-weight: 500; font-size: 11px; line-height: 1.45; margin-right: 16px; margin-left: 4px;" th:switch="${callout}">
    <img th:case="'New'" th:src="@{img/new.jpg}" alt="New" width="104" height="22" border="0" style="display: block; margin: 0; outline: none; border: 0; font-family: 'Montserrat', sans-serif; text-decoration: none; color: #323232; font-weight: 500; font-size: 11px; line-height: 1.45;">
    ...
</p>

I call my template using Context. and the code looks like this. String output = templateEngine.process(Constants.TEMPLATE_FILE_NAME, new Context(Locale.getDefault(), variables));

I can't get this image to show up on my email. I have my html file in src/main/resources/templates and my jpg files in src/main/resources/static/img

I've also tried using 1) th:src="@{/img/new.jpg}" which throws an error org.thymeleaf.exceptions.TemplateProcessingException: Link base "/img/new.jpg" cannot be context relative (/...) unless the context used for executing the engine implements the org.thymeleaf.context.IWebContext interface (template: "email_template" - line 346, col 164)

(I guess I can't simply use Context-relative URLs if I just do new Context(...).)

and 2) th:src="@{../static/img/new.jpg}"

How do I use WebContext instead of Context or is there any other solution to this?

afzal
  • 33
  • 4

0 Answers0