【问题标题】:thymeleaf email template background-image not showing upthymeleaf 电子邮件模板背景图像未显示
【发布时间】:2019-05-04 20:02:12
【问题描述】:

我有这个基于 thymeleaf 的电子邮件模板:

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
    <title th:text="#{email.reset.title}">reset title</title>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
</head>

<body th:style="'background: url(' + |cid:background| + ') no-repeat'">
    <div style="margin:110px 0 0 50px;">
        <div style="min-width:10px;min-height:300px"></div>
        <img style="display:block;margin-top:110px" th:src="|cid:logo|" />
        <img style="display:block;margin-top:110px" th:src="|cid:background|" />
    </div>
</body>

我已经定义了两个这样的变量:

message.addInline( "logo", new ClassPathResource( "mails/images/logo.png" ), "image/png" );
message.addInline( "background", new ClassPathResource( "mails/images/background.png" ), "image/png" );

img 标签中的两张图片在发送的电子邮件中正确显示,但作为body 背景的相同图片未显示。不知道为什么。

在 java spring 中使用百里香。

【问题讨论】:

  • 你有什么解决办法吗?不幸的是,我现在遇到了同样的问题。
  • @Krish 找不到任何简单的东西,所以我放弃了它
  • 只有当我在浏览器中登录多个谷歌帐户时,它才在我的情况下工作。它与一个谷歌帐户工作正常。所以我认为这不是我们的错误:)

标签: java spring thymeleaf


【解决方案1】:

几个月前我做了类似的事情,我使用

是这样的:
<body th:style="'background: url(' + |cid:${background}| + ') no-repeat;'">

如果没有美元符号 $ 和大括号,我无法正确使用该变量。

我希望这会有所帮助。

【讨论】:

  • 不幸返回 cid:null
【解决方案2】:

我遇到了类似的问题,正在使用 like

<body th style="margin: 0; padding: 0; background-image: url(images/background.png)"
      data-th-style="|background-position: center; background-repeat: no-repeat; background-size: cover; background-color: #ccc; background-image: url(cid:background)|"
>

它适用于手机,但不适用于桌面。我不确定是否是因为质量。 仍在努力。 试试这个,如果它的工作。

【讨论】:

  • 对我来说同样的问题,徽标显示在移动设备上但不显示在桌面上:(