Embedding an Image in a Flow Outlook Email Action
Sending out emails from automated systems that include images has been a long established capability from all the popular bulk email platforms. The Microsoft Outlook client allows you to paste in images or construct signature blocks that contain images such as your company logo.
In the context of the Microsoft Flow product there is currently a partial gap in this capability in the sense that you can’t do it from a toolbar function. And while I expect this to be closed in the near future, I am going to show you two way on how to close that gap now in this blog post.
If you search for Send Office 365 email Actions (not Triggers) you will get the following list. Let’s take a look at the first one, the Send an Email, then we will look at Send an Email (V2) (preview).
This Action is the original version that offered Body input with plain text, no formatting or styling supported. It did you give you the option of specifying that what you had entered was HTML marked up text and would interpret the HTML tags and render it accordingly. This was a handy way of creating a nicely formatted and stylized body message that would look like a Web page. It wasn’t very friendly to use as you had to construct the content in an HTML editor and then copy and paste it into the Body field. But it did offer a way to embed images into an email that could be sent out via Flow.
The next iteration of the Action took either two steps forward and one step back, or one step forward and two steps back depending on your requirements to support images. If you were to ignore including images inside of the emails, it is definitely two steps forward. The Send an email (V2) (Preview) Action provides an excellent foundation for future enhancements by the Flow Team.
The new Action is a Rich Text Editor which allows the creator to easily stylize the text from a tool bar and insert hyperlinks to external websites. It does not allow the insertion of images as a tool bar function. It also removed the capability of inserting HTML markup. This will be the Action we want to kick off from to be able to use for when we want to include images. Scroll on down to the next section and I will walk you through how to do it.
Business Objective: Create a Flow that you can run from within the Dynamics 365 UI to send a nice looking email to selected Contacts wishing them a Happy New Year and letting them know about the 2019 Product Roadmap.
Step 1 – Construct the Flow with a When a Record is Selected Trigger and then add the Send an email (v2) (Preview) Action. Personalize the email with the First Name of the Contact using the Dynamic Content feature. Insert text and bold it to highlight the two locations where an image needs to be inserted – Product Roadmap Image Here and MVP Image Here.
Step 2 – This is where it gets a little geeky and we have to create the HTML Markup. Follow these steps:
- Login into OneDrive and upload to a Folder the image(s) you want to use in the email.
- Click on one of the images in OneDrive Folder which will take you to a screen as shown below.
- From that screen you will see a toolbar at the top. Click on the Embed action.
- This will open up a panel on the right hand side of the screen. Check mark the Include HTML tags box.
- Copy all the text in the box and paste it into Notepad.
- In Notepad, replace all the Double Quotes with the Single Quote. Why? When we paste it into the Flow JSON in a later step, the JSON doesn’t like double quotes.
Note – click on the image to see a larger size version if it is squished on your screen
Step 3 – Now we have a link to the image, but we need to fix it up so if the recipient clicks on it, the Roadmap page will open up in their browser.
<img src='https://zer0ew.by.files.1drv.com/y4mqweDBv0ZOA-ADU_PEycf-Wc2p9jvUrXNCbMrXEsupYEaiyfTZZNCRfhQsokNR-YLp_rjx2M-7rNQHO3arFFku7bNsfMRIfvbPbMpsUagb67bmFmb1h0cmfSyMabJInsR4mdhnvUyHXSIkGHey8NnTfZtuuyDhL40IwQz9zpWx6PKQnDF6mszlOGJvdKcthfJV01Ivgk5psMBlLQJB85RWw?width=952&height=772&cropmode=none' width='952' height='772' />
To do this we need to wrap the link into an href HTML tag. So we need to insert it into <a href=’ target url here’> image source from above here </a> The finished tag is shown below.
<a href='https://aka.ms/flowroadmap/'><img src='https://zer0ew.by.files.1drv.com/y4mqweDBv0ZOA-ADU_PEycf-Wc2p9jvUrXNCbMrXEsupYEaiyfTZZNCRfhQsokNR-YLp_rjx2M-7rNQHO3arFFku7bNsfMRIfvbPbMpsUagb67bmFmb1h0cmfSyMabJInsR4mdhnvUyHXSIkGHey8NnTfZtuuyDhL40IwQz9zpWx6PKQnDF6mszlOGJvdKcthfJV01Ivgk5psMBlLQJB85RWw?width=952&height=772&cropmode=none' width='952' height='772' /> </a>
Step 4 – Now we need to do essentially the same thing for the MVP logo except we don’t need the clickable hyperlink.
<img src='https://zer1ew.by.files.1drv.com/y4mwLjYMlXV0qRkN61r2CTXidi5kutAa49Nr33A7uep1M5PQyO3LaJxpWrN0GocdeeiEMmrsQeV308fQWqzVWztyni30eO7Et4_WMYsiexQD6HdHq0xDixVCLi6UyQbVbYAjyr9YknBBZHF6Acz6uubdUEIdtXs9cmqIB4fLEiM-g4KCM0x8peCFgitHwNK-7uOuqs0pN7Yr2ix-W6p7ssf3Q?width=48&height=20&cropmode=none' width='48' height='20' />
This is where we can diverge on the process with two measurably different approaches – one for Citizen Developers and another method for those Professional Developers out there that like to go in and tweak the code. I will outline the Citizen Dev approach first.
Citizen Developer Method
Step 5 (CitDev) – Between the When a record is selected Trigger and the Send an email (V2) (Preview) Action add two Initialize variable Actions. Fill in the fields for each as shown in the screen shot below. Then take the code snippets you created using the methods in Steps 3 & 4 and insert the HTML markup into their respective Initialize variable Actions to replace the Bold Image Text placeholders.
Step 6 (CitDev) – Now insert the Dynamic Content values into the Send an email (V2) (Preview) email action to replace the placeholder text. After that scroll on down to Step 7.
Professional Developer Approach
Step 5 (Professional Dev) – We need to modify the JSON file and replace the placeholder Bold Image Text with the code snippets from Steps 3 & 4. There are two ways to do it. Export the Flow to a folder on your computer, unzip the file, find the JSON file, edit it, save it, zip it back up and then import it back into Flow. That is not the way I am going to show you.
I am going to use John Liu’s Flow Studio to edit the JSON. FYI, I won’t be showing the whole step by step process here as it would balloon the length of this blog post even more. I will be creating a companion video in a few days that walks through it and will update the blog post with a link to it. Quite frankly, the images won’t make much sense to you unless you have his app.
Step 6 (Professional Dev) – Find the placeholder text and then cut, copy and paste in the HTML. Then Save.
Before
After (most doesn’t fit on the screen but you get the idea)
Step 7 (Professional Dev) – If we look at the Action in Flow now, the placeholder text is gone but the HTML markup won’t be visible. We just see some white space. All is good.
Step 7 – Now go into Dynamics 365, select one or more Contacts, select the Flow to send the email. I have selected myself so I can show you the finished product.
Step 8 – Ta Da!!!!!!! Success. Now you have the basic process. Have fun running with it in your own Flows.
Thank you so much…. You helped me a lot
Hello,
The solution seems to be great. However, the Embed action is not available to me after saving the image jpg file on OneDrive.
Is there something wrong? Is there a way it could be resolved?
Thanks
Which version of OneDrive are you using?
Excellent explanation of how to do it!
Did it and it worked!
Thanks, Jerry!