Spring Mail – Sending Email with Freemarker HTML Template Example

You may also like...

Leave a Reply

2 Comments on "Spring Mail – Sending Email with Freemarker HTML Template Example"

avatar
  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.