gpt4 book ai didi

java - 图片附在带有 thymeleaf 的邮件中

转载 作者:行者123 更新时间:2023-11-30 06:27:39 38 4
gpt4 key购买 nike

我正在使用 thymeleaf 发送带有模板的邮件,但图像正在附加,这是不可能发生的。这是我的代码:

HTML:

<!-- I need put the image backgroud via css!-->
<body th:style="'background-image: url('+ |cid:${background}| +')'">
<!--my image-->
<img src="../../../static/images/email/topo_email.png" th:src="|cid:${logo}|"/>
</body>

JAVA:

//the main code of the method is here:

String emailFormatado = contatoEmail.getDescricao().replace(System.lineSeparator(), "<br>");
contatoEmail.setDescricao(emailFormatado);

Context context = new Context(new Locale("pt", "BR"));
context.setVariable("contatoEmail", contatoEmail);
context.setVariable("logo", "logo");
context.setVariable("background", "background");

try {
String corpoEmail = thymeleaf.process("admin/mail/EmailResposta", context);
MimeMessage mimeMessage = mailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true, "UTF-8");
helper.setFrom(contatoEmail.getUsuario().getEmail());
helper.setTo(email);
helper.setSubject(String.format("Mensagem de respota"));
helper.setText(corpoEmail, true);

helper.addInline("background", new ClassPathResource("static/images/email/background_email.png"));
helper.addInline("logo", new ClassPathResource("static/images/email/topo_email.png"));

mailSender.send(mimeMessage);
} catch (MessagingException e) {
logger.error("Erro enviando e-mail", e);
}
<小时/>

一切正常,但图像已附加。我希望你可以帮助我。

最佳答案

解决办法:

在我放置图像变量的 java 代码中,缺少图像类型:

helper.addInline("logo", new ClassPathResource("static/images/email/topo_email.png"), "image/png");

关于java - 图片附在带有 thymeleaf 的邮件中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46798365/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com