Spring Mail – Sending Email with Freemarker HTML Template Example

You may also like...

8
Leave a Reply

avatar
5 Comment threads
3 Thread replies
4 Followers
 
Most reacted comment
Hottest comment thread
8 Comment authors
Gustavo CinqueMemoryNotFoundTùngIbrahim AlTamimibgdc 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”);

Tùng
Guest
Tùng

I got error : “javax.mail.AuthenticationFailedException: 454 4.7.0 Too many login attempts, please try again later…”
What should I do? :((

Gustavo Cinque
Guest
Gustavo Cinque

Hi! Seems to be a nice way to load html files. I’m facing a little problem, though. It seems like none of my ftl files are being cached. At one point, after failing to retrieve the ftl file from cache, the code goes and searches for a _.ftl, but even with a file corresponding that name in the correct folder it doesn’t work. Inside the Configuration#createTemplateCache() method, the loader points to the correct templateLoaderPath set on the FreemarkerConfig. One question, is the folder hierarchy correct in this example? Because mine is exactly the same, even the folder’s name. Error: java.io.FileNotFoundException:… Read more »