Power Automate Desktop Example - Downloading Image From Email To Network Drive

2021-06-25_20-38-09

After watching the RPA (Robotic Process Automation) demo from Steve Winward Real-Life Use case using AI Builder Form Processing with Power Automate Desktop I have been looking for ways to utilize Power Automate Desktop Flows in order to make my life a little easier. Yesterday like every day I started clicking through the emails that I receive from my kids schools. I open each email, download the image, then move the image to a network drive on my computer. This takes me a few minutes every day but my kids are worth it :) This scenario was a perfect one for me to automate using Desktop Flows since they can access the network drive on my desktop.

The basic flow of the solution will be as follows:

  • A Power Automate Cloud Flow will be triggered to run whenever a new email comes into my Gmail account with a specific tag.
  • The Cloud Flow will gather up all the information needed to run the Desktop Flow
  • The Cloud Flow call the Desktop Flow by connecting through an On-Premise Data Gateway that is installed on my desktop.
  • The Desktop Flow will download the image and save it to my network drive.

Prerequisites

In order to complete all this you will need the following.

  • Power Apps Environment. If you don’t have one you can try it out by signing up for a Developer Plan here.
  • Power Automate Desktop. This needs to be installed on your computer, download it here.
  • On-Premise Data Gateway. This is how the online Power Automate cloud flows will connect to your Desktop Flows. You can download it here. Instructions for installation can be found here.
  • Application registration for Gmail within the Google console. You cannot use the default shared application because it’s not compatible with the Encodian actions or any other external Flow actions. Learn how to create this here.
  • API key for Encodian to utilize their Regex action in your flow. You can sign up for one here

Inspecting the Email

For this example I’m using emails supplied by a service called Tadpole which my kids school uses to send out images and notification. The first thing I had to do was use the developer tools (F12) within the browser to help me understand how the urls were formatted for the service and how they worked. After searching through the html I figured out the formatting and found that if i used one of the parameters found in the one link for d=t that it would download the full size image.
2021-06-25_19-32-46

Add Gmail Label and Filter

The first thing i did was went into my Gmail and created a new label for the incoming emails. The name of the service the school use is Tadpole so i made that my label. I think created a filter so that all emails coming from the Tadpole address would get that label applied. All of this is important because otherwise your Flow will run on everything in your Inbox which could be a lot of messages and you could end up running into API limits for Flow depending on your license.

2021-06-25_15-23-53

Create the Desktop Flow

The desktop flow will download the image using it’s url and save it to to the network drive. To get started open the Power Automate Desktop application you have installed and create a new Flow.

The first thing we need to do is define the input variables we will use. We will later be passing the data into these variables from the Cloud Flow created later.
2021-06-25_15-30-37

Now we can start adding actions to the Desktop flow. The first one will be a Convert text to datetime action which we will use to transform the input variable from the flow into a datetime which will allow us to do some string formatting faster.
2021-06-25_15-34-46

Next we will do some formatting on our date time to create flow variables which we will use later.
2021-06-25_15-37-10

2021-06-25_15-39-25

Check to see if the network drive folder exists and if not create it.
2021-06-25_15-42-17

2021-06-25_15-45-39

Finally we will download the file using the url provided as an input variable and save it to our network drive folder.
2021-06-25_15-48-55

We have now successfully created our Desktop flow. Make sure you save it and then you can test it by clicking the Run button in the editor.
2021-06-25_15-51-50

Create the Cloud Flow

Now that we have created our Desktop Flow we need to run it any time an email arrives in our Tadpole inbox. This flow also needs to extract the rrl for the image and pass that information to the Desktop Flow.

Here is a high level outline of the Flow we are going to build.
2021-06-25_17-08-39

Now let’s get started building! We will start by creating a solution in the maker portal.
2021-06-25_16-08-48

Add a new Cloud Flow.
2021-06-25_16-12-41

Setup for our Gmail trigger. Again if you haven’t created a new Application within the Google console you should do that now using the instructions located here.
2021-06-25_16-14-53

2021-06-25_16-24-09

2021-06-25_16-21-51

All the emails that contain images have kids names at the beginning of the subject so i will set up a condition to make sure that this is an image email and also extract that data so i can use it to save the image later.
2021-06-25_16-27-59

2021-06-25_16-32-34

We need to get all the urls contained in the email so we will use the Encodian Regex action here to find them. Here is the Regex you will need to find all the urls in the body of the email.

(?:(?:https?|ftp):\/\/|\b(?:[a-z\d]+\.))(?:(?:[^\s()<>]+|\((?:[^\s()<>]+|(?:\([^\s()<>]+\)))?\))+(?:\((?:[^\s()<>]+|(?:\(?:[^\s()<>]+\)))?\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))?

2021-06-25_16-37-10

Now that we have all the urls in the message we need to look at them all and see which one is the image. We will also do some parsing of the url to make sure we get the full size image by appending the ?d=t property to the url.
2021-06-25_16-46-10

2021-06-25_16-49-05

Last but not least we will connect to the Desktop Flow we created earlier and pass in all the information we have collected from the email.
2021-06-25_16-58-56

Test It!

In order to test my flow I added another Gmail filter that would tagged any email coming from myself with my kids names in the subject. This allowed me to then forward old email to myself for test processing.

2021-06-25_20-05-06

2021-06-25_20-05-43

Comments

Post a Comment

Popular posts from this blog

Add User As Local Administrator On Domain Controller

An error occurred while applying security information to

Display ADFS 2.0 Forms Authentication Login Page Instead of Windows Authentication Prompt