Issues embedding inline images in HTML Exchange Email

Hello. I’m working on a project that involves sending out a dynamically generated HTML email that contains two images in an HTML email template and I’ve run into an issue. The two images are always fixed & never change, however they cannot be hosted online using a public image hosting site, thus I am required to either use the image’s content ID to embed them or encode them with base64 in the email itself (which I’ve yet to look into).

After searching online, I ran into this post which creates an attachment variable using the image path, then generates a content ID for the attachment which is passed into the body of the email along with passing the attachment variable as an in-argument to the send mail activity. While this worked for a single image, if I attempt to replicate it and add a second image with a new variable/contentID/argument/etc. and run it again, the first image appears in its place (showing 2 images total, but the same image in both places) regardless of the img’s src tag being that of the new content ID for that image & both being passed as attachment arguments correctly.

After some further troubleshooting from this point, I’ve found that whichever image’s content ID is passed first via the attachment arguments, that is the image which appears in all places in the mail body, regardless of anything. The second image won’t end up embedded, but instead simply sent as a regular attachment.

I then attempted using a slightly different approach I found here which is a method to attach more than 1 attachment to an email, and integrated it with the previous workflow. This time, I created a mailMessage variable as well and attached the images via looping through an array containing the image file’s paths/names & adding them via an Invoke Method. Both images successfully attached so I assumed I could embed them by accessing them similar to an array element such as mailMessage.Attachements.Item(0) but this resulted in the same issues from above with both images being the same one regardless of any changes made. I’m starting to run out of ideas as to why the email body only shows duplicates of a single image rather than two different ones even though everything points to two separate images - any ideas? I’m all ears…

Unfortunately I cannot link the code due to it being internal for a company, but the above two posts have links to workflows that are easy to manipulate and replicate the issues I’ve listed.

tl;dr Want to embed two images into an HTML email body w/o using a public image hosting site. Images will attach as regular attachments just fine. Attempted 2 attachment variables & unique contentID variables per image, but this results in both inline images being the same image. Attempted to attach them via Invoke Method & then accessing the attachment elements on the mailMessage variable, but again, both embedded img tags appear as the same image regardless off the src tag differences or element differences (ex: Item(0) vs Item(1) - if I pick Item(3) it says out of bounds as it should).

Any help would be appreciated.
`

1 Like

Bump here.

I was trying to recreate this yesterday, cause I am using an image hosting site and before that I was using an image hosted on a company website. The problem I find with the image hosting site though is that the recipient gets untrusted images that they must click on.

So I am interested in this other method too with inline images. I am little concerned that attaching images will get in the way of other attachments for the recipient, but am curious how well this works.

I am using a combination of Invoke Method and Invoke Code to generate a Mail Message with dynamic Attachments. If I can recreate your issue by using the Attachment imagecontent id, I’ll let you know.

Regards.

Hey @Jon4than,

So I took your idea to use the content id number of the attachment and implemented it in a workflow snippet that I recreated from a workflow I’m actively using, which generates the email as a Mail Message then uses Invoke Code to send SMTP.
it’s working for me

It embedded the images as intended. I figure you can make some adjustments as needed, but essentially, it uses an array of image filepaths to attach, loops through those images and appends them to a body string using the content ID inside the loop. - you may want to make adjustments to how the “size” of the images are calculated though.

I hope this helps.

test_imagesinbody.xaml (32.3 KB)

Let me know if you have any questions about this upload.

Regards.

1 Like

@ClaytonM
First of all, thank you for posting this! I have been trying multiple other methods, unsuccessfully. Second, I have a couple clarifying questions (I am new to this and don’t completely understand everything that is happening in this workflow).

  1. I have three images that I need to attach, but they need to go in specific places within my email, not one right after another. Below is a screenshot of our current HTML, and we are using the path in each of the highlighted areas. How do I properly replace this with the right image from your code?
  2. I am compiling a new list of recipients each time the process runs. When I try to put the variable in, it gives me an error. How do I properly set up the argument to take in my string variable?

Thank you!

Hi Clayton,

I’m running into this issue now in that the email shows up as a forward using smtp mail messages:

Appears as a forward, when I click in it looks like this

Background:

This is my BODY String:

How can I show the html image using the invoke code method but also make it so that it doesn’t appear as a forwarded message where the user needs to click into the email to view the actual email?

I think the Send SMTP has this problem when using a MailMessage type variable.

Instead, you can try using Invoke Code to Send via SMTP. - this works well for myself

image

image

image

I also used Invoke Method to add the ‘TO’,‘CC’,‘BCC’, and attachments.
And, assign activities for the ‘From’,‘Body’, and ‘Subject’

So once it’s all stored into the MailMessage, the Invoke Code sends it with the server and port.

Regards.

@jdahlinger were you ever able to solve your question? Let me know and please clarify with any error messages, so I can help further.

Regards.

@ClaytonM I tried multiple ways to handle this, but it kept displaying images at the end of the email only and not actually in the body where I defined them.

The workaround we came up with was to create images of our headings that were going between each picture, and then attaching six images instead of three. It isn’t pretty, but it works.