Microsoft Flow: How to embed an image in an email

Microsoft Flow: How to embed an image in an email

Task:

Using Microsoft Flow, trigger the sending of an email with an embedded image.

  • The image will be stored in a SharePoint Library
  • We will assume you have already created connections to:
    • Office 365 Outlook
    • SharePoint

Steps:

  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 the 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/_Company/Images/EmailSignature.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=”My Image” />
      2. Next click between ‘64,‘ and ‘” alt
      3. Add dynamic content
      4. Select: Expression fx
      5. Enter .$content
      6. Placing your 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
  5. Save the Flow
Microsoft Flow: How to embed an image in an email - showing the expression: <img decoding=

*Here is the full code/expression:

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

So what tripped me up?

On my first attempt I tied using the File Content variable directly within the body of the email, only to see binary… Note: This works fine when attaching the file as an ‘attachment’ (see Attachments Content).

Plus I struggled to find a way to convert binary to base64. That was before I realised I didn’t need to do all that work, hence this blog post…