Images are attached in mail

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

Images are attached in mail

rhadamez
Hello everyone,

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

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);
}

-----------------------------------------------

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

rhadamez
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");
Reply | Threaded
Open this post in threaded view
|

Re: Images are attached in mail

Soumya
This post was updated on .
Thanks rhadamez .
This solved my issue.

Regards,
Soumya
Reply | Threaded
Open this post in threaded view
|

Re: Images are attached in mail

rhadamez
I'm glad that helped you!

Regards : )
Reply | Threaded
Open this post in threaded view
|

Re: Images are attached in mail

reachsf2
I am trying set background in email body.
I did same way but background image not set.

Getting image as attachment.
And when i inspect element coming as like this:

<div style="background-image:url(https://mail.google.com/mail/?ui=2&amp;ik=5cd776d4bb&amp;attid=0.0.1&amp;permmsgid=msg-f:1632321932195609868&amp;th=16a72c261f993d0c&amp;view=fimg&amp;permmsgid=msg-f:1632321932195609868&amp;sz=s0-l75-ft&amp;attbid=ANGjdJ8F6sBb6cY-J3nP9I863iScMhzDHBRWzD4T6GL8ifdYj1FSlSaHwtu8kMugcQuRY99NicoKzrIy6nN4b8Lg4VGfgOJc_ltoTxgE1_ys4o30DFIueJvKk_Aa3zQ&amp;disp=emb&amp;zw)">
         dsghdgshdghsgdhsgdhgshds
         <br>
         <br>
        dkshdshdjsdhs
 

</div>