It sounds easy but believe me it is not so easy that it sounds like. There is no direct way that you can embed an image when you are drafting “Send Email” action even when you are planning to use HTML code in email body. There is a way to add a Image html tag but question is what will be the URL/SRC for same. Suppose you want to place image url which is exposed on internet, accessibility set to public, in that case you saved your time. Just use the URL in image tag and it will work.
So just wanted to mention one more important thing here. Email can we viewed by multiple means: MS Outlook or from Browser. The behavior in both the cases will be different. I have observed the behavior that sometimes when email is opened using browser it renders images perfectly but when same email was opened using MS Outlook app, images shows just cross marks. May be due to the reason the images can easily be accessible using browser but Outlook it may require some extra steps.
After spending two or three days, trying different options, I finally got a solution which works in all cases.
Problem:
Using Microsoft Flow, trigger sending of an email with an embedded image.
- The image will be stored in a SharePoint Library/One drive
- We will assume you have already created connects to:
- Office 365 Outlook
- SharePoint/Outlook
Solution:
- Create a new Flow:
- Select: +New > Instant—from blank
- Click: Manually trigger a flow
- Add the 1st actions:
- Search for SharePoint > Get file content using path
- Select the action
- Site Address: either select or ‘enter custom value’
- File Path: enter the path from the site collection (e.g. ‘/Style%20Library/DemoFile/EmailCompanyLogo.jpg’)
- Add the 2nd actions:
- Search for Variables > Initialize variable
- Select the action
- Name: Enter ImageTag
- Type: Select String
- Value: This is the trick bit!*
- Enter: <img src=”data:image/jpeg;base64,” alt=”CompanyLogo” />
- Next click between ‘64,‘ and ‘” alt‘
- Add dynamic content
- Select: Expression fx
- Enter .$content
- Placing you cursor before the .$content click: Dynamic content
- Locate and select File Content
- Click OK
- Add the 3rd and last actions:
- Search for Office 365 Outlook > Send an email
- Select the action
- To: enter your email address
- Subject: Microsoft Flow: How to embed an image in an email
- Body: <p>This is my test email, you should see an image below</p><p></p>
- Click between the last <p></p> tags
- Click: Add dynamic content
- Locate and select the ImageTag variable
- Is HTML: Select Yes(Note: you may not able to find this option in new versions of the action. In new versions, there is option looks like “</>” at top right corner of the action which converts body in html. Here is the screen shot for same)
Save the Flow
*Here is the full code/expression:
<img src="data:image/jpeg;base64,@{body('Get_file_content_using_path')['$content']}" alt="My Image" />
Note: The other way to implement the same requirement is to attach as attachment to the email action. Provide file content as Attachment Content and image will be rendered as usual.
Please feel free to hit like button in case you find the content of this bog helpful.
Happy PowerAutomating !!
Thanks for this. I attempted this, but it did not work.
LikeLike
Appreciate you posting this and the level of detail you have included. Unfortunately, when the workflow runs an image with a question is included instead of the actual image. These are the steps and configuration:
1. Added ‘Get file content used path’ action. Linked to image in SharePoint library. Ensured the account connected to the workflow had access.
2. Added ‘Initialize variable’ action. Configuration includes Name: ImageTag, Type: String, Value: .
3. Added ‘ImageTag’ variable to email between
and
and ensured HTML was turned on.
LikeLike
Hi Joshua,
As was mentioned earlier, Power Automate adds additional quotes, I solved this by removing all quotes from the ‘initialize variable’ value leaving everything as src=data:image/… and alt=MyImage
Hope it helps,
Michael
LikeLiked by 1 person
I removed the quotes and the logo is now showing in the email. Thank you for your help with this. 🙂
LikeLike
Can you please specify from where we need to remove Quotes OR else put the original format I which we need to specify the expression.
Thank You
LikeLike
Hi Joshua, thanks for trying this solution. It must be issue with quotes. You can check with flow history and check if images content is properly fetched or not. If still that solution does not work then there is one more way to implement this.
Another solution will be, you just need to expand attachment sections and provide image name and content as an attachment to the email. Then under body just try to place the content and it should work !
LikeLike
Amazing, works perfectly, thanks for saving me long hours of troubleshooting
LikeLiked by 1 person
Here is the modified Code that worked for me, just copy paste
LikeLike
Not Sure why the code above did not paste, probably because of html tags, please add opening closing brackets
Opening Bracket img src=data:image/jpeg;base64,@{body(‘Get_file_content’)[‘$content’]} alt=MyImage / Closing Bracket
LikeLike
ensured HTML was turned on–where this option is available in ms flow?
LikeLike
@sreenu, this option is there when you open advanced option of “Send Email” action. But don’t worry if you do not able to see this option under advanced options just make sure html is supported when you send email. Hint: MS has added button in send email actions for html body content.
LikeLike
I could not locate the below option? Could you please point where this option located?
– Is HTML: Select Yes
Also, inside Initialize variable, in the name text box, do I need to manually type the name as “ImageTag” in the textbox?
LikeLike
Hi Santos, Thanks for trying my solution. Yes, MS has updated the action now IsHTML is removed. There is option looks like “” at top right corner of the action which converts body in html.
Also, about ImageTag, it is just a variable name you can type it same or type whatever name you like.
LikeLike
It doesn’t work for me at all. $content is not available for me to choose. Mine is the GIF file and it works on either Web browser or the desktop version depending on who I send it to. I have tried to solve this but so far is having no luck.
LikeLike
You are thebest
LikeLiked by 1 person
Thanks Wendy !!
LikeLike
Hi. Thanks for this solution. After some minor changes, I got this working. I have another requirement you might like to consider. I put two images into an email. One was automatically resized to the full width of the email by Outlook. The other was fine and not resized. Any ideas?
LikeLike
Hi Dave, Thanks for trying this. About the size of the image, I think it should be dependent on resolution(height and width) of the image. I have a workaround that you can try here is by adding specific height and width in the image tag. Here is an example of what I am saying:
I did not tested this but logically it should work. Wish you luck !
LikeLike
Thank U… it works!
LikeLike
Hi, i modified the flow. Instead of sending an email i create a new OneNote Page with that Code… but it works only for small pictures. For bigger pictures like 3 or 4 MB i get a failure .. and OneNote says “RequestEntityTooLarge.” Do you have any soloutions?
LikeLike
compress the image 🙂
LikeLike
Hi, on Outlook it works like a charm, but on iOS (iPhone) I get chinese characters insteed of the image.
Does anyone have a fix for that?
LikeLike
You are a the MAN!!! Thanks 🙂
LikeLike
Amazing! Thanks a ton!
I was going crazy trying to figure out how to make the image viewable for everyone in my team. This worked!
LikeLike
Hi, Thank you the solution. It works great but it’s too big in width and height and solution on that?
LikeLike
HI, you just need to add width and height properties to the IMG node something like this
Regards
RD
LikeLike
Thank you so much. This works for me.
LikeLike
Hi, thank you so much for this walk through it worked beautifully
I have figured out how to make it working with variable inputs, but I am struggling to embed variable images.
I have tried putting the imgtag in an array, but that isn’t working.
Any suggestions would be greatly appreciated.
LikeLike
Great article. Thank you! Just wondering is there any way to attach a pdf file using HTML code? I am trying to create a calendar event from flow and add an attachment in the calendar invite. I need to attach a pdf file instead of an image.
LikeLike
Any chance of getting this to work with gifs please? Particularly gifs that animate? I have changed the prefix of the image src to data:image/gif;base64, but it is displaying nothing in my email just like if I remained with data:image/jpg;base64
LikeLike
It is working fine except for the mobile outlook version. there the image stays blank. any suggestion for this?
LikeLike
nevermind, added a space before the alt in “alt=”My Image”” and it works now.
the Var made without quotes
LikeLike
hi my name is nosh in case you responding to me
i have tried everything but i am still getting an email with only text
i used one drive, and duplicated everything you said except for the alt–> alt=”picture” and i used HTML in the email. here is the code written in value when i peeked it: “open brackets img src=”data:image/jpeg;base64,@{outputs(‘Get_file_content_2’)?[‘body’].$content}” alt=”Picture5” /close brackets
LikeLike
super, working with out any issues
LikeLike
I am getting
Action ‘Get_file_content_using_path’ failed
with onedrive image which I have permission to. What could be wrong?
LikeLike
You made my day. Thank you !
LikeLike
Hi! How would I place multiple images in the email? Thanks!
LikeLike
According to
https://powerusers.microsoft.com/t5/Building-Flows/How-to-get-the-content-of-images-from-SharePoint-that-I-put-into/td-p/1592764
the expression is
outputs(‘Get_file_content’)?[‘body’]?[‘$content’]
So when I look at the output of ImageTag using above, it looks like
<img src=”data:image/jpeg;base64,/9j/4eFFRXhpZgA…"
Is that right? Not working for me yet. Do let me know how I can debug where I went wrong?
LikeLike
ah…it turns out my file was an image saved with extension jpeg but was not a jpeg OR it was a jpeg which was too large.
I found a comment at
which lead me to resave the jpeg with lower resolution and the problem is working.
LikeLike
Hi,
I never thought it would be so difficult to perform simple task. I tried your way but only getting small cross image in result. I am trying to get mi image from Power Bi report.
Can you help on this.
LikeLike
Works like a charm. thank you for the solution. Made it so easy.
LikeLike
what will happen if SharePoint column is empty?
not all fields in my form will have an image.
LikeLike
Email receiving with no image on main content. any idea what is the issue ? the image is in onedrive and its jpeg .
LikeLike