我使用百日咳发送带有模板的邮件,但图片正在附加,不可能发生。这是我的代码:
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);
}
一切都正常工作,但图像是附加的。我希望你能帮助我。
答案 0 :(得分:0)
解决方案:
在我的java代码中,我放置了图像的变量,缺少图像类型:
helper.addInline("logo", new ClassPathResource("static/images/email/topo_email.png"), "image/png");