I include this in my velocity file. but it is not working,
< img src="cid:src/resources/imageContent.jpg" />
You can follow the guide here.
For example, try this in your Velocity template file:
<img src = "cid:${cid}" alt = "Foo">
And in your Java code, try:
URL url = new URL("image.png");
String cid = email.embed(url, "Foo");
Map model = new HashMap();
model.put("cid", cid);
When your server is running you can get path till server from request.getContexPath();
So here you just need to provide rest path of the image. I have done this for my demo application like this.
<img border="0" alt="Test" src="${projectPath}/images/logo.jpg"/></a></td>
Now you have to set value of projectPath to your projectPath which you can get by request.getContexPath();
Now create one Map in which you have to add Key which will keyword that you have used in .vm file. For this example, we have used projectPath.
Map map = new HashMap<>();
map.add("projectPath",request.getContexPath());
map.add() // other value that you want to replace in vm file
After that create instance of VelocityContext load this map with constructor argument like this
VelocityContext velocityContext = new VelocityContext(map);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With