In my previous question (it is solved Images in tags don't show on mail when send template using Thymeleaf) I was not able to display inline images in my email.
But now, when it all working I find another issue.
In my code I use MimeMessageHelper method addInline(), also I need to attach a file to mail, but it is not attached.
When I send mail without addiInline() method, the file is attached correctly. Also in mailbox, I receive mail I see inline files when mail is closed (I think it's not correct, I'll add an image below) but when I open mail, the template view is nice and without those files, but not shown attached file. I share with you all my code, maybe I doing something wrong
MimeMessageHelper helper = new MimeMessageHelper(mmessage, true, "UTF-8");
File file = new File("C:\\Users\\redxp\\Downloads\\demo
(1)\\demo\\src\\main\\resources\\file.pdf");
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
helper.addAttachment("Shop & Go invoice " + LocalDateTime.now().format(formatter), file);
//I tried to attach in different places - on beginning, bellow e.t.c
helper.setFrom(FROM_ADRESS_DEF);
helper.setTo("****here mail*****");
helper.setSubject("Your Shop&Go Invoice");
ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
templateResolver.setPrefix("/templates/");
templateResolver.setSuffix(".html");
templateResolver.setTemplateMode(TemplateMode.HTML);
templateResolver.setOrder(1);
TemplateEngine templateEngine = new TemplateEngine();
templateEngine.setTemplateResolver(templateResolver);
Context context = new Context();
context.setVariable("name", "Volodymyr");
DateTimeFormatter formater1 = DateTimeFormatter.ofPattern("dd.MM.yyyy");
context.setVariable("date", formater1.format(LocalDateTime.now()));
String process = templateEngine.process("bonnetjeEN", context);
helper.setText(process, true);
helper.addInline("headershopgo", new ClassPathResource("static/img/headershopgo.png"));
helper.addInline("ln", new ClassPathResource("static/img/in.png"));
helper.addInline("inst", new ClassPathResource("static/img/insta.png"));
helper.addInline("fb", new ClassPathResource("static/img/fb.png"));
helper.addInline("aln", new ClassPathResource("static/img/aldi.jpg"));
and received mail:
That are those files what I see when mail is received bot not opened and they putting on template.
