How to - Embed an Image in the Body of a Mail

@mcorru, that’s a very interesting question.
I’m getting there doing it with Thunderbird by using base64 encoding of the image; clicking Insert ->HTML, then in the dialog box adding <img src=“<your base64 encoded data file, which should start with ‘data:image/jpeg;base64’>” /img>
I have a rudimentary recording I’m not ready to post yet, because using “Type Into” to get the variable into the dialog box takes - literally - over 5 minutes for an 18kb base64 file.

However, since you’re using Exchange, and can use Exchange Web Services, you might find a starting point from the samples here.

However, where the example shows:

   Dim html As String = "<html><head></head><body><img width=100 height=100" & _
                    " id=""1"" src=""cid:Party.jpg""></body></html>"

you might replace

src=""cid:Party.jpg""

with

src=""<your base64 encoded data file, which should start with 'data:image/jpeg;base64'>""

I don’t have access to Exchange, so I apologize for being of little help. I will post my Thunderbird results when they are fit to be seen.

EDIT: Here’s a quick-and-dirty but working Thunderbird example. You may have to tweak file paths and selectors, but it does work fine and is not slow.

SendImageInEmail.zip (15.9 KB)

The files should be SendImageInEmail.xaml, project.json, and data_helloworld.src (which contains the base64 encoding of the jpeg).

Just as a rundown of the workflow:

  1. Open Thunderbird (as it is, if Thunderbird is already open it won’t work, but this is just a test anyway)
  2. Find the ‘Write’ pushbutton (I don’t click it, because I want to send hotkeys).
  3. Send ‘Alt-m’ as a Hotkey to open the ‘Message’ menu
  4. Send ‘n’ as a Hotkey (and not Ctl-N, as the menu says)
  5. Read the text file ‘data_helloworld.src’ which contains the base64 encoded jpeg.
  6. Assign it to the variable ‘imageString’
  7. Assign “<img src=” & imageString & " /img>" to ‘htmlString’.
  8. Set ‘htmlString’ to clipboard (this to get around the long wait from ‘Type Into’
  9. Attach the Thunderbird ‘Write’ window (this may not be necessary, but it’s in there and at least works)
  10. Click into the message area of the email where you want the image to go (I just clicked at the top).
  11. Send ‘Alt-i’ as a Hotkey to open the ‘Insert’ menu in the ‘Write’ window
  12. Send ‘h’ as a Hotkey to open the HTML dialog box
  13. Click into the ‘editable text’ dialog which is for the HTML
  14. Send ‘Ctl-v’ as a Hotkey to insert clipboard contents.
  15. Click ‘Insert’ button (I should probably have added a delay here for bigger image files).
  16. Added a Message Block to block the thread, since this is just a test and not for production.

Regards,
burque505

(I had this image already base64’d, so that’s what I used)

2 Likes