如何在Spring Boot thymeleaf电子邮件模板中指定表格背景图片

时间:2019-04-30 19:13:51

标签: html5 spring-boot thymeleaf javamail

我将图像保留在文件夹 resources / static / img /

我的css和html模板中的html:

.bgImg {
    background-image:url('cid:asset_bg');
}

<table width="100%" border="0" cellpadding="0" cellspacing="0"
                align="center" class="bgImg" >

</table>

我在Java代码中设置如下内联内容:

helper.addInline("asset_bg", new ClassPathResource("/static/img/asset_bg.png"), MimeType.png.contentType);

但是在邮件中,我将其作为附件获取,而不是在后台。

我在网上签入并尝试了其他方法:

<table width="100%" border="0" cellpadding="0" cellspacing="0"
    align="center" class="mobile2 mailBgImg" th:style="background-image:url('cid:asset_bg');">

**Could not parse as expression: "background-image:url('cid:asset_bg');"**  

<table width="100%" border="0" cellpadding="0" cellspacing="0"
    align="center" class="mobile2 mailBgImg" th:style="'background-image:url(' + ${cid:asset_bg} + ')'">

**Exception evaluating SpringEL expression: "cid:asset_bg"**

<table width="100%" border="0" cellpadding="0" cellspacing="0"
    align="center" class="mobile2 mailBgImg" th:style="'background:url(' + @{/static/img/asset_bg.png} + ');'"> 

**Link base "/static/img/asset_bg.png" cannot be context relative (/) or page relative unless you implement the org.thymeleaf.context.IWebContext interface (context is of class: org.thymeleaf.context.Context)** 

如何在Spring Boot thymeleaf电子邮件模板中指定表格背景图像?

0 个答案:

没有答案