Power Automate: Embed an image in an email


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:

  1. Create a new Flow:
    1. Select: +New Instant—from blank
    2. Click: Manually trigger a flow
  2. Add the 1st actions:
    1. Search for SharePoint > Get file content using path
    2. Select the action
    3. Site Address: either select or ‘enter custom value’
    4. File Path: enter the path from the site collection (e.g. ‘/Style%20Library/DemoFile/EmailCompanyLogo.jpg’)
  3. Add the 2nd actions:
    1. Search for Variables > Initialize variable
    2. Select the action
    3. Name: Enter ImageTag
    4. Type: Select String
    5. Value: This is the trick bit!*
      1. Enter: <img src=”data:image/jpeg;base64,” alt=”CompanyLogo” />
      2. Next click between ‘64,‘ and ‘” alt
      3. Add dynamic content
      4. Select: Expression fx
      5. Enter .$content
      6. Placing you cursor before the .$content click: Dynamic content
      7. Locate and select File Content
      8. Click OK
  4. Add the 3rd and last actions:
    1. Search for Office 365 Outlook > Send an email
    2. Select the action
    3. To: enter your email address
    4. Subject: Microsoft Flow: How to embed an image in an email
    5. Body: <p>This is my test email, you should see an image below</p><p></p>
    6. Click between the last <p></p> tags
    7. Click: Add dynamic content
    8. Locate and select the ImageTag variable
    9. 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 !!

43 thoughts on “Power Automate: Embed an image in an email

  1. 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.

    Like

    1. 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

      Liked by 1 person

        1. 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

          Like

  2. 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 !

    Like

  3. 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

    Like

    1. @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.

      Like

  4. 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?

    Like

    1. 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.

      Like

  5. 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.

    Like

  6. 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?

    Like

    1. 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:
      CompanyLogo

      I did not tested this but logically it should work. Wish you luck !

      Like

  7. 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?

    Like

  8. 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?

    Like

  9. 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!

    Like

  10. 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.

    Like

  11. 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.

    Like

  12. 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

    Like

  13. 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

    Like

    1. 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.

      Like

  14. 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.

    Like

  15. Email receiving with no image on main content. any idea what is the issue ? the image is in onedrive and its jpeg .

    Like

Leave a comment

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