Skip to content

Add support for dynamic datasource resolution (file/url/classpath) for embedded images in HTML body #260

@distributev

Description

@distributev

Is there any API available to achieve this?

Currently, in order to embed an image a user would have to modify both the HTML template and the Java code like this

java

currentEmailBuilder.withEmbeddedImage("smiley", new FileDataSource("smiley.jpg"));

and then the corresponding HTML code

<p>Smile!</p><img src='cid:smiley'>

this is fine but in many situations users are allowed to modify the HTML template but the java code would not be available to be modified by the users; thus would be useful to allow dynamically embedding images in emails only by referencing the image files in the HTML code.

I also used the apache commons email and they provide the option, only be modifying the HTML template to include images available both locally and also on remote websites.

Apache commons email has something like a DatasourceResolver which could be either DataSourceFileResolver or DataSourceUrlResolver like this

email.setDataSourceResolver(new DataSourceUrlResolver(new URL("http://website.com")))

email.setDataSourceResolver(new DataSourceFileResolver(new File("./templates")))

and then the user would only be expected to provide the HTML code like this

<img src="template1/images/logo.png"/> - starting from the ./templates parent directory

or from the website

<img src="http://website.com/template1/images/logo.png"/>

Here is the apache commons email API for the resolver

https://commons.apache.org/proper/commons-email/javadocs/api-release/index.html

Is there something similar available in simple-java-mail?

P.S - I believe that simple-java-mail has a very good API and I intend switching from apache commons email for the additional features which your API provides like delivery / read receipt and other things. I also intend to use email-rfc2822-validator for validating email addresses. Thank you for the hard work you put in this project.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions