I have a piece of code where I am trying to send emails templated with thymeleaf to show data and image(as logo) inside the email.
Here is my function to send the email:
public void sendingemailtest() throws MessagingException, IOException{
String recipientName = "Hero";
final Context context = new Context();
final MimeMessage mimeMessage = this.mailSenderTest.createMimeMessage();
final MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true, "UTF-8");
context.setVariable("name", recipientName);
context.setVariable("image", "logo.jpg");
helper.setFrom("from email test");
helper.setSubject("testing sending email with image");
helper.setTo("to email test");
final String htmlContent = this.springTemplateEngine.process("registration-email", context);
helper.setText(htmlContent, true);
helper.addInline("logo.jpg", new FileSystemResource("/logo.jpg"), "image/jpg");
this.mailSenderTest.send(mimeMessage);
}
And in thymeleaf template I use th:src="|cid:${image}|"
to reference the image and th:text="${name}"
to reference the name
All is working and the email is sent but I have one issue here: the email when received is showing as containing attachment but I dont want to show the image as attachement. How to do that as I see a lot of companies send emails containing images but not showing attachment sign on the side of the email.
Please help!