Search code examples
spring-mvcvelocity

I can't display my image in my temlate.vm (velocity)


I'm trying to send an email with a template using springMvc. I used Velocity to disay the template. The problem is that the image in the cannot appear in my email. And I'm sure that my src is incorrect! Here is my template.vm

<html>
    <body>
        <h3>Hi ${user.login}, welcome to the Chipping Sodbury On-the-Hill message boards!</h3>
<img src="fond-bleu.jpg">
        <div>
            Your email address is <a href="mailto:${user.emailAddress}">${user.emailAddress}</a>.
        </div>
    </body>
</html>

Solution

  • Your problem has nothing to do with Velocity, and I'm pretty sure your URL is not correct:

    When displaying an image in an email, you have to choose between three solutions:

    • hosting the image somewhere (then the image URL will be something like http://myserver/...)
    • linking the image as an email attachment (in which case the image URL will be something like cid:{0})
    • embedding the image in base64 (in which case the image URL will be something like data:image/jpeg;base64,...).

    There are pros and cons for each method.