This post explains how to embed images inside an email sent from a Power Automate flow. This is a common requirement and can cause frustration depending on the requirements.
Generally, people want to include images stored within SharePoint, and this will be the basis of this blog post.
There are a few different methods, and I will explain the differences as we go through the post. If you prefer, here is a video explanation:
The file I am going to use for my test is in a SharePoint document library, it is called powerAutomateTestImage.png:
The full link to the file is:
https://accendo1.sharepoint.com/sites/PowerAutomateText/Images1/powerAutomateTestImage.png
Provide a simple link to the file in your email
This scenario is simple. On a client that is signed in to Office 365, you can specify the URL of the image in SharePoint and it should show in the email client:
This works well in the Outlook Web client, but not in other clients as the file is not reachable. So unless all of your clients are using Outlook on the Web, I do not recommend this method.
Embed the image content directly into the email with Base64
This method is much more reliable as the actual content from the image is sent within the email. So there is no need for the receiver to retrieve the image from SharePoint.
The file content is retrieved with the “Get file content using path” step. Then injected into the email as base64, with these expressions:
outputs('Get_file_content_using_path')?['body']['$content-type'] outputs('Get_file_content_using_path')?['body']['$content']
The complete image expression would be:
<img src="data:@{outputs('Get_file_content_using_path')?['body']['$content-type']};base64,@{outputs('Get_file_content_using_path')?['body']['$content']}" />
This method works really well, however some mail clients do not support base64 encoded images within the email body. For example, gmail does not show any base64 encoded images.
Another disadvantage of using this method is that the if the image is large, the email will large also. So be mindful of the size of the image that you are sending.
Use Power Automate as a HTTP Web Server
The most compatible way of embedding images in an email is to a publicly available image on the internet.
Uploading the image to a web server or CDN is best. But if you really want to use SharePoint as your source, it can be done. Its quite easily achieved by creating a flow which will serve image content via HTTP.
See this very simple flow:
This flow responds to a HTTP request with a reference to the Image in the URL. The picID in the URL refers to the ID of the image in the SharePoint document library:
The link to my HTTP Server Flow is:
https://prod-48.westeurope.logic.azure.com/workflows/59c5a92ccebe4f97adfd52eb6cf213a8/triggers/manual/paths/invoke/picID/{picID}?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=DNrMaouJY_Sifq8DRvbeWcuDl8TGKgeFpvP9NxDmOcQ
By modifying the {picID} to the ID of the image you want to serve, your private SharePoint Image will be accessible to the public. The test image used in this flow is ID 24, so this is the link to the dynamically served image. By changing the ID in the URL, a different image would be served to the client.
So now, getting back to our original email flow, we can modify it like so:
Now I can send the email to almost any client and it will be able to display the image. There are a couple of downsides to this method:
- It requires a Premium Power Automate license to use the “When a HTTP Request is received” action.
- The flow will execute every time someone looks at the email. If you are sending the email to many recipients, it will use a lot of flow capacity.
You could modify this flow to track if emails have been read, by embedding the recipient address in the URL. When the email is served to the client, you know the email has been read.
So what method should you use?
The method you should use to embed an image mostly depends on the capabilities of the recipient:
- Don’t use the first method, unless every one of your recipients is using Outlook Web Access.
- The base64 embedding method works well for the majority of clients.
- The HTTP method works well for all clients. But is more work to implement and not suitable if you are sending to many recipients at once.
- For transaction emails, I recommend using Sendgrid with Power Automate instead, it is much easier and produces a beautiful result.
Let me know in the comments how you get on and what method you choose!
Leave a Reply Cancel reply