Try for free Book a demo

Logic App Best Practices, Tips, and Tricks: #27 How to embed HTML images into emails

Microsoft Azure

4 Mins Read

Welcome again to another Logic Apps Best Practices, Tips, and Tricks. In my previous blog posts, I talked about some of the essential best practices you should have while working with the Azure Logic App. Check out these Logic App tips and tricks!

Today I will speak about another useful Best practice, Tips, and Tricks that you must consider while designing your business processes (Logic Apps): How to embed HTML images into your email using Logic App Designer.

how to embed html images in logic app designer

How to embed HTML images into emails using Logic App Designer

What we pretend to achieve is how we can, inside Logic Apps, embed an image in the body of the email and send it without the image being blocked by Outlook or Gmail. It seems simple, but it has some tricks on it.

Most of the times, people try to do is to add an image inside the body of the email like this:

Sending an email in Logic app

However, that will not work since the HTML code you place will be converted as text, and the result will be this:
how to embed html images in logic app designer
Workaround to fix this issue

A simple workaround to fix the issue above is to go to the Code view of your Logic App and fix the HTML code inside the body property. When you access the Code View, you will see that the image HTML code you added is expected to act as a string:

Sending an email in Logic app

Go ahead and fix that to be:

  • <img src=\”https://blog.sandro-pereira.com/wp-content/uploads/2017/01/sandro-pereira-blog-logo.png\”>
    Sending an email in Logic app

And save your Logic App. If you try again, you will see that a picture will be presented in your email instead of an HTML text.

Email sent through Logic App

However, this workaround is a little bit weird since if you go back to Logic App Designer, you will not see any reference to the picture even though it will be there:

how to embed html images in logic app designer

So, this workaround is difficult to read and maintain in the long run.

Approach 1: Using a variable with a link to the image

The first approach you can implement is to use a variable to contain the image HTML code, in this case:

  • <img src=\”https://blog.sandro-pereira.com/wp-content/uploads/2017/01/sandro-pereira-blog-logo.png\”>

Initialize image variable

And in our email action on the body, we will make a reference to this variable:

Send an email through Logic App

If we save and test our Logic App, you will see that we end up receiving an email with the image inside:

how to embed html images in logic app designer

This approach works, however many email clients may block your images or ask if you want to download them:

how to embed html images in logic app designer

So the main question is: is there a better way? Yes, there is!

Approach 2: Using a variable with an image in bas64

This last approach, and for me the best approach, is to use the same strategy of the previous approach, but instead of having an image URL, we provide an image in base64.

If you don’t know how to convert an image in base64, you can use this website: Base64 Image Encoder to accomplish that, and use the data info to add in your <img> element

how to embed html images in logic app designer

In my case, I now need to add the following code to my variable value:

  • <img src=”data:image/png;base64,iVBORw0KGgoAAAA … … … NSUhEUgRK5CYII= /> (it is a big base64 string)

how to embed html images in logic app designer

And then keep the same code in the email action:

how to embed html images in logic app designer

Now, if we save and test our Logic App, everything will work as expected, and the images will not be blocked in our email clients:

how to embed html images in logic app designer

I hope you enjoy this developer tip and stay tuned for the following Logic App Best practices, Tips, and Tricks.

Related reading

This article was published on Apr 6, 2023.

Azure Logic Apps - Request Demo CTA

Related Articles