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

Hi everyone,

I am asking for help on this subject since every other solution I’ve found browsing this forum did not work out for me.
I can’t enbed an image in the body of a mail (i am using Exchange), every approach I’ve used so far has been unsuccesful, in particular:

  • the ref=cid: approach (with the file referenced file attached) gave me the “the link is missing etc.” error

  • the base64 approach returns a blank mail (and not the aforementione error, maybe it loaded a blank image?)

I’d like to know how you managed to embed an image in the body of a mail,

Thank you

2 Likes

Hi,
You might look into HTML code. You can send the body as HTML with the image embedded. I don’t really have a sample. I know you can create a message and save it as .htm then look at the code that way to find the part that embeds your image.

1 Like

Hi Clayton, thanks for the answer!
I tried that way, i referenced the image in the html using the same approach proposed in this forum, by setting the image’s Contenct ID, referencing it in the html code and attaching the referred image to the mail. However this approach does not work, i get a “the linked image cannot be displayed …” error. Maybe my syntax is wrong that’s why I’d like to ask for some snippets from someone that managed to send a mail with an embedded image.

1 Like

@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