Power Automate Desktop: Launch Outlook, Download Email Attachments, Move email to subfolder

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
thank you greetings and salutations in some of my previous videos that I Linked In the description below I demonstrated how to search for emails in an inbox of a certain criteria download Associated attachments and move the email into a different folder in the mailbox I showed how to accomplish this using Python and Powershell in today's video I will show you how to accomplish this using power automate desktop version now there is probably a less convoluted way to do this especially with power automate Cloud version but I will demonstrate how I accomplish this using the free version follow along with me and let's begin if you are not familiar with power automate it is a service offered by Microsoft it helps you create automated workflows between applications and services that can sync files get notifications collect data and much more the power automate desktop is a free version of the service and installed by default on Windows 11. if you don't have it you can download it by visiting the link in the description once installed you can launch it like any other application this is how this home screen will look if you click on the plus new flow button we can begin creating the flow so we can go ahead and give this flow a name I will give it the name of get attachments and select create it takes a few moments to create a flow area and here we are on the left will be all our actions that we can perform in the center will be our table where we construct our flows and on the right will be our variables now our goal is to read emails in our inbox that have a subject of daily reports and download their attachments to a specific folder so these emails will be targeted and their attachments downloaded to a folder that identifies the sender so we will download each attachment into a subfolder that is the sender's email address once the attachments has been downloaded then we want to file the email into this completed subfolder our mailbox is using Outlook foreign there is an Outlook tab if we expand it we can see our available options our first step would be to launch Outlook so you can either double click on it or drag and drop here we will be presented with the variables this produces and you can change the name I will keep it as Outlook instance and hit save if you click on the three dots and hit edit you can also edit it this way foreign next we are going to retrieve email messages from Outlook our Outlook instance will be the name we specified in our launch accounts will be the email address of the uh inbox we are searching mail folder will be inbox foreign there are several options under retrieve we want all email messages we can leave the mock as red option enabled our only requirement is that the subject contains daily report so fill that in and our attachments we want to save attachments and specify the directory that we want to save them into and hit save foreign we then will want to close Outlook and specify the name of our Outlook instance which is already filled in okay let's run this and see what it does okay we got this error message failed to launch that's because Outlook is open let's close Outlook and run it again foreign targeted emails and downloaded all six attachments great okay now we need to Loop over all our downloaded email attachments and create a folder that identifies the sender then move the email into that folder first thing let's expand loops and see our options let's go to a regular Loop now we can start from a variable or manual entry so let's start from the number one now when we we want to go over the same number of our targeted emails unfortunately there's a built-in variable for this click the X and expand retrieve emails and you will see account variable this will give us the number of emails we targeted okay great and over each iteration of emails we will increment by one this will be stored in our Loop index variable hit save okay so we have our Loop that will Loop over all our emails now we want to create a folder that belongs to the sender so expand folder and we have an option to create a folder put that between our Loop and enter the location of where you want the folder to be created I have an attachments uh directory that I want the folders in [Music] the folder name will come from a variable but how do we get the sender's name over on the right here if you select more actions and view to retrieve emails you will see more variables click on more on one of the emails you will see a from set selection so the format to get the sender will be retrieved emails bracket the index of the email which will be a loop index and from so it will look like this we are using Loop index -1 because we are starting counting from one but the index starts from zero so we have to take that into consideration our variable will be produced in a new folder okay but we only want to create the folder if it doesn't exist already so let's add a check that checks if the folder exists and if not create the folder let's drag over if folder exists options and change exists it doesn't exist and the folder path will check will be our same variable as before so only if the folder doesn't already exist will be created and make sure the create folder is between the folder exists option and its end we want to move attachment files so let's look at our variables again okay so there's a variable to get the full name which is full name and also just the name of the attachment let's use the full name but as you can see here noted by the zero there can be multiple attachments and we specify each attachment by number so let's create a loop for us to Loop over all the attachments that are associated with a given email let's go a loop condition and start our first operand at zero it should go for just as many attachments as the associated email has unfortunately there's no way to get the kind of attachments from our variables but there is another way if we hit cancel here and go to our Loops let's create a for each Loop here we will use this to count over all our attachments and store it in a variable we will go over all our attachments that we can get from this variable and that will output to our current item variable we just need a count of attachments for an email so let's add the attachments to a list and then count our list so let's create a new list and add it outside our Loop because we can just clear it with each iteration next create a for each Loop and add the attachments to the list we just created this will get our current attachments foreign to add will be our same variable and our list will be the newly created lists and right before the end of our Loop we will clear the list foreign will have a built-in count variable that we will reference that we can use to Loop over our attachments associated with that email now we create a loop to Loop over all our attachments associated with an email to move those specific attachments first thing we want to do is to declare a variable that we will use to increment up to the same count of items listed in our list so let's declare a variable and call it I set its value to zero then let's create another loop that will start from I and go to the count of the elements in our list which will be a number of attachments so our first operand was going to be I the operator will be less than because we are starting at zero and our second operand will be our list count save that now we want to move our attachment files from our downloaded directory to the associated senders folder so add our move files action our files to move will be set to our directory plus the name of the current attachment variable with I being a variable to identify the attachments the destination folder will be a directory plus ascenders from identifier variable and if the file exists let's overwrite it save that okay so We're looping over attachments to move them using I but we will have to tell I to increase by 1 after it moves a file so let's add an increment for I after our move set our variable to I and increase by one so that should Loop over and move our attachments the same number of times as the amount of attachments now after we have moved all our attachments we want to move the email to indicate we have already downloaded the attachments so let's add our process email action after our Loop our instance is set our account will be the email address of the inbox our email messages to process will be our current email message variable the operation would be to move email messages and the mail folder would be a completed folder under our inbox okay let's go over this logic all right first step is to launch Outlook our second step is to retrieve our targeted emails that have certain subjects and download those emails into our temp directory then we create a list then we Loop over all those emails associated with the attachments we downloaded we then create a folder associated with the sender if it doesn't exist if it does we skip this then after each attachment associated with that email we add it to our list we do this to get the count of attachments because there's no not a built-in way to get attachment account then we set a variable I to zero and loop over from I to our list count we move our Associated attachments to ascendus folder in our directory once we move over all our Associated detachments we move the email to a completed folder and clear our list and we do the same stats for the remains of the emails then we close Outlook okay in theory that looks good let's run it and see what happens our Outlook shows five emails that should be targeted three different senders with one containing two uh different attachments and our directory is clear our folders and attachments okay close Outlook and run the flow and let's see what happens okay it completed with no errors let's check our directory we have three folders and attachments in each [Music] great let's check our Outlook and in our completed folder we have our five targeted emails great that works okay that brings us to the conclusion of this video hopefully you found it useful if you have any specific use cases that you would like to see a video for using power automate let me know in the comment section please like And subscribe and thanks for watching this has been brought to you by AIP Solutions
Info
Channel: AIP IT Solutions
Views: 2,898
Rating: undefined out of 5
Keywords:
Id: JNE96L0D7lQ
Channel Id: undefined
Length: 17min 17sec (1037 seconds)
Published: Fri Feb 24 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.