Images are attached in mail

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view

Images are attached in mail

Hello everyone,

I'm sending a mail with images, but the images are being attached, it cannot happen. Well, here is my code:


<!-- 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}|"/>


//the main code of the method is here:

String emailFormatado = contatoEmail.getDescricao().replace(System.lineSeparator(), "<br>");
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.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"));
} catch (MessagingException e) {
	logger.error("Erro enviando e-mail", e);


Everything is working corretly, but the images are attached. I hope you can help me.

Sorry if I make mistake, first post.
Reply | Threaded
Open this post in threaded view

Re: Images are attached in mail

The solution:

In my java code, where I put the variable of the image, was missing the type of image:

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