Power Automate: How to embed an image into an email

I see this question a lot in the forums. How to embed an image into an email? The connector enables us to send attachments, but when it comes to embedding the image in the email, we need to do some additional steps. So first, I’ll show you the whole Flow and then explain the concepts if you’re interested.

I’ll use the “Send an email notification” action for this example, but Outlook’s “Send email” action works the same way, so you only need to replace the action, and you’re good to go.

Here’s the full Flow.

Be careful copying the steps since there’s a lot of “gotchas”. I explain them below, but here’s the heads-up.

Let’s explore each step on how to embed an image.

Get the image

The Flow is quite simple. You “only” need to fetch the file contents and send them. I’m using the “Get File Content” action because I know the file I’m sending, but you can also use the “Get File Content using Path” action.

So far, so good. Now that we have the file let’s generate the email.

Generate the email’s body

This is the part that many struggles with (myself included) while trying to embed an image. First, I tried to attach the image to the email. Unfortunately, it didn’t work since we want the image to be displayed in the email and not attached to the email.

Emails are sent, most of the time, as an HTML file. So the next step was to generate the HTML that will display the image. I know what HTML I want to generate:

<img src="logo.png" alt="My Logo">

Even with it attached, the image was not displayed. But, again, it makes sense because we’re sending the file as an attachment, so there’s no reference between the attached image and the one I’m sending.

The third time the charm. Now we enter the tricky part. HTML also enables you to send the files as base64. As you know, files are stored in binary, but we need to add it as HTML, so as text otherwise, your email client won’t be able to parse it. Base64 defines the set of rules that convert the binary to text so that we can use it. This is an oversimplification, but I want for you to understand the “why.”

So here’s the same as above but converted to base64.

 <img src="data:image/png;base64,@{outputs('Get_file_content')?['body']}" alt="My Image" />

As you can see, we have the definition that we have an image in base64 and a png. Then we append the string of characters that build the image so that your email client can understand them and generate the image. We get that from the “Get File Content” action, so we add the string in a “Compose” action, insert the file contents and send the email.

Here what the email looks like:

Ok, it looks like crap. But it gives us a clue. You see binary, and we know that we need to provide text. This is because the “body” is not the file content. It contains more, so let’s look at the result of the “Get File Content” action.

This looks a lot better, but we don’t have a way to select in the “Dynamic content” pane the “$content.” So we need to add it ourselves. Here’s the HTML:

<img src="data:image/jpeg;base64,@{body('Get_file_content')['$content']}" alt="My Image" />

Here’s the result.

Looking good!!!

Let me explain a bit further one detail that you may overlook at first. If you select the item from the “Dynamic content” pane, you’ll get:


But notice above that we have:


Notice again the result of the “Get File Content” action.

We want what’s inside the body and content, so we need to define that we want the body of something and not the output of the action. The output is the binary file that we don’t need for our purposes.

I want you to be aware of this, since you may have this issue in the future, so now you know the solution.

The email

I skipped this part in the previous section because this is the easiest part. But there’s a trick. When you add the “Send an email notification” action, Power Automate shows you the following:

Above, you see the area where you can write your email. But if you look closer, this is not HTML. Instead, it’s a rich text editor that will generate the HTML for you. We don’t want that, so we need to explicitly tell Power Automate that we want to generate the HTML ourselves.

You’ll see this:

It looks more what we need, so since we built the HTML in the previous step, we only need to add the output here, and we’re done.

Final thoughts

You may be wondering that this is a lot of text to explain how to embed an image, but as you noticed, many things can go wrong and things that we can also do wrong. Of course, when you know the solution, it becomes much easier, but I wanted to take some time and explain to you the concepts and why things fail so that, if they happen again, you can quickly know what’s wrong and fit it.

Have a suggestion of your own or disagree with something I said? Leave a comment or interact on Twitter and be sure to check out other Power Automate-related articles here.

Photo by Carl Heyerdahl on Unsplash

Manuel Gomes

I'm a Project Manager with experience in large projects and companies. I've worked in the past for companies like Bayer, Sybase (now SAP) and I'm currently working for Pestana Hotel Group.

View all posts by Manuel Gomes →

One thought on “Power Automate: How to embed an image into an email

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: