java - Freemarker embed image on ftl -
i trying embed image on freemarker ftl template send email, i've based on question feemarker writing images html, did exact same thing question said, email being generated this
what may causing error, , how fix it?
my template looks
<img alt="my image" src="${imgasbase64}" />
the image chart, , base64 string, called imagebase64str, via primefaces javascript function generates base64 of chart image, pass the bean , pass parameter template
string encoded = imagebase64str.split(",")[1]; byte[] decoded = base64.decodebase64(encoded); string imgdataasbase64 = new string(decoded); string imgasbase64 = "data:image/png;base64," + imgdataasbase64; emailparams.put("imgasbase64", imgasbase64);
string encoded = imagebase64str.split(",")[1];
suspicious. looks changing base 64 string generated in different way. image png or it's in format? think if remove split , emailparams.put("imgasbase64", imagebase64str);
may work.
however need consider solution won't work many email clients. according link https://www.campaignmonitor.com/blog/email-marketing/2013/02/embedded-images-in-html-email/ base64 embedded images not supported on few major email clients, web , standalone, including gmail , outlook. given common email clients don't want deliver solution doesn't work on them or of users gonna unhappy.
imo best bet host images in server , use qualified urls in freemarker template.
an alternative using attachment , reference them in html source explained here: https://stackoverflow.com/a/36870709/2546299 require changes on way emails sent (need add attachments) may not suitable case.
Comments
Post a Comment