How do I insert picture to outlook body message in Power Automate?

Problem

A customer complained that they used the following action to send an email with the image, but the email recipient cannot see an email in the outlook client.

Customer’s original way to send an email with picture to send an URL to SPO site.
The Outook client showed the image like shown above

Step by Step Solution

In summary you cannot send an SRC attribute to an url for the outlook client. To protect the users the outlook client will block the image url. You need to pass an image as base64 encoded SRC like the following.

Sample base64 img tag for the send email

<img 
src="data:image/png;base64, *****"
alt="an image desc">
</img>

WHERE:
***** is the base64 long string.

Step #1:

Get a file from any library where your image resides. e.g. in SiteAssests library. The output of this action will be In the following format.

The output of the Get File content.


{
    "$content-type": "image/jpeg",
    "$content": ".9jsd…. LONG CHARACTERS IN BASE64"
}

Step #2:

Create a Compose action to get the SRC value for IMG tag with base64. The expression is a string concatenations.

Using concat function create the SRC attribute value.

concat (
    'data:image/png;base64, ',
    outputs('Get_file_content_suing_path')?['body']?['$content'])
)

Step # 3:

Use the above compose to send an email action.

IMG tag uses the SRC from the compose output.

<img
src="outputs('Compose_to_make_SRC_of_image_a_base64')"
alt="hey look I can work like this">
</img>

Result image was rendered in outlook client

About Pankaj

I am a Developer and my linked profile is https://www.linkedin.com/in/pankajsurti/
This entry was posted in Power Automate, Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s