Spring Mail – Sending Email with Freemarker HTML Template Example

You may also like...

5
Leave a Reply

avatar
3 Comment threads
2 Thread replies
4 Followers
 
Most reacted comment
Hottest comment thread
5 Comment authors
Ibrahim AlTamimibgdcgqrdqqfdKentChris Recent comment authors
  Subscribe  
newest oldest
Notify of
Chris
Guest
Chris

Thank you, this was very helpful!

I noticed your example code didn’t work out of the box for me, but after two small adjustments it was fine:

  • In EmailService.java, we had to use helper.addInline("logo.png", new ClassPathResource("memorynotfound-logo.png")); instead of addAttachment.
  • The addInline call needed to be moved after the setText call, instead of before it.

After this, we got emails coming out with attachments shown inline just as in your example.

Kent
Guest
Kent

This guide could be improved. If using helper.addInline versus helper.addAttachment make sure to call helper.setText before any calls to addInline otherwise the image will not be properly added.

gqrdqqfd
Guest
gqrdqqfd

mail.getModel() is not defined

bgdc
Guest
bgdc

mail.setModel() is not defined too

Ibrahim AlTamimi
Guest
Ibrahim AlTamimi

Map model = new HashMap();
model.put(“name”, “Memorynotfound.com”);
model.put(“location”, “Belgium”);
model.put(“signature”, “https://memorynotfound.com”);