Converting HTML with locally referenced images, to HTML email linking inline to attachments?

0

Let's say I have an HTML page, that refers to local images, which I'd want to send as an HTML email from Thunderbird. My question is: what would be the right method to achieve that?

To demonstrate that in an example, let's grab a couple of random images from imgur, and set up a local web server, that will serve them and the page that refers to these images:

mkdir /tmp/test
cd /tmp/test
wget -q https://i.stack.imgur.com/bTC3W.png -O image1.png
wget -q https://i.stack.imgur.com/tyDiL.png -O image2.png
wget -q https://i.stack.imgur.com/7BRTc.png -O image3.png
# add content to mynote.html later manually:
touch mynote.html
# start local HTTP server:
python3 -m http.server 8000

And inside mynote.html, let's say I have this content:

<!DOCTYPE html>
<html>
<body>

<h1>My notes</h1>

<p>Here is one image:</p>

<a href="image1.png"><img src="image1.png" alt="image1" style="max-width:100%;"/></a>

<p>Another image is here:</p>

<a href="image2.png"><img src="image2.png" alt="image2" style="max-width:100%;"/></a>

<p>And here is the final image in this document:</p>

<a href="image3.png"><img src="image3.png" alt="image3" style="max-width:100%;"/></a>

</body>
</html>

With the HTTP server started, I can now open http://127.0.0.1:8000/mynote.html in a web browser - this is what it looks like in Firefox:

firefox-mynote


Now, what I basically do now, is Select All in the page shown in Firefox (66.0.2), then I stop the web server; then I start a new HTML e-mail in Thunderbird (60.6.1), and I try and paste the content there; this is initially how it looks like (Windows 10):

thunderbird-html-01

One may think, that all is fine, as the images are visible - however, they all refer to local IP addresses, which can be confirmed by double-clicking them, and referring to Image Properties:

thunderbird-html-02

... so if I send this e-mail, it is almost guaranteed that the recipient will not be able to see the images inline.

To work around this, I use Choose File to refer to the local source image, and then check "Attach this image to the message":

thunderbird-html-03

... and I hit OK. Note that if, after this, I double-click the image again, the image location is shown to be something like:

data:image/png;filename=image1.png;base64,iVBORw0KGgoAAAANSUh...kJggg==

I do this for all the images - and so, thinking all is fine now, I send the e-mail. Note that here I might get a "HTML Mail question" message:

thunderbird-html-04

... to which I choose "Send in HTML only".

Regardless, when I open the copy in my Sent Mail folder, I can see the images are not present:

thunderbird-html-05

In fact - even if the attachments are attached correctly - the inline images in the HTML email still refer to 127.0.0.1!


So, as more specific questions:

  • Is there anything I could do differently in Thunderbird in the above procedure, so that inline images will refer to the embedded attachments?

  • On the other hand, is there a command line tool, that - provided the web server is active, so the images are present - could convert the HTML page to, say, .eml?

I'd imagine that tool would be called as (pseudocode):

$ ./html-2-eml-tool mynote.html --out mynote.eml

or

$ ./html-2-eml-tool http://127.0.0.1:8000/mynote.html --out mynote.eml

... which would correctly embed or attach the images in that .eml, so I can just open that .eml in Thunderbird, hit "Edit As New Message", and then send it?

sdbbs

Posted 2019-04-03T09:53:40.913

Reputation: 334

No answers