Skip to content
Advertisement

How to send email with inline image using ThymeLeaf

I’m trying to send an email with an inline image using ThymeLeaf and Spring, but so far no success. The email sends, but the inline image won’t show in the email.

The project is not web-based (not a website), but is a desktop stand-alone, not mobile

This is how I get the image file:

JavaScript

My service class:

JavaScript

The HTML:

JavaScript

Advertisement

Answer

This works perfectly:

Just add a link to the image hosted on an external server away from your desktop. Use inline CSS, instead of CSS classes.

This website will help you convert CSS classes to inline CSS, Premailer.Dialect.

Avoid any fancy CSS, just use the most basic. Floating (like float: left;) should be avoided as much as possible if you’d like your HTML mail to flow easily, even in mobile devises and other smaller screens.

Include NekoHTML in your project libraries, and change your Spring spring.xml to:

JavaScript

Sample this:

JavaScript

Service Class:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement