Subscribe

UiPath StudioX

The UiPath StudioX Guide

Tutorial: Saving, Renaming, and Moving Attachments

In this tutorial, we will create an automation that saves the attachments to all the emails in an Outlook Search Folder to your computer, then moves the files to another folder on your computer and renames them by adding today's date to the file name. To rename the files, we will use a formula in the default Excel Workspace available in StudioX.

We will create a project and start by adding an Outlook Account Card to indicate the Outlook account to use. In the card, we will add a For Each Mail Message activity and then the common scenario Iterate through mail attachments to indicate that we want to save the attachments for each email and then process each file after it is saved. Iterating through each file in the folder where the attachments are saved, we will then add a Write Cell activity to copy the file name and edit the name in the Excel Workspace, and a Move File activity to move the file with the updated name to another folder.

Step 1: Create two folders on your computer and a Search Folder in Outlook.

  1. Create two folders named In and Out at the root of the C: drive on your computer.
  2. Open Outlook, then right-click Search Folders in the Folder pane and select New Search Folder.
  3. In the New Search Folder window, select Create a custom Search Folder > Choose.
  4. In the Custom Search Folder window, enter "Last week's attachments" in the Name box and then select Criteria.
  5. In the Messages tab of the Search Folder Criteria window, from the drop-down menus next to Time select received and Last Week.
  6. From the More Choices tab, select Only items with and then one or more attachments from the adjacent drop-down menu.
  7. Click OK three times to close the windows and save the search folder.

Step 2: Set up a project.

Step 3: Add the Outlook account to the project.

  1. In the Activities panel, select the Outlook tab, and then double-click Outlook Account Card. An Outlook Account Card activity is added to the Designer panel.
  2. In the activity, the default email account is already selected in the Select mail account field. If you want to use a different account, select it from the drop-down menu.
    In the And reference it later as field, leave the default value Outlook as the name under which to refer to the account in the automation.
604

Step 4: Iterate through the messages in the Outlook Search Folder.

  1. In the Activities panel, drag the For Each Mail Message activity and drop it inside the Outlook Account Card.
  2. In the For Each Mail Message activity, click plus button on the right side of the Use mails from field, and then select Outlook > [Search Folders] > [Last week's attachments]. Your selection is displayed in the field as Last week's attachments.
    You have indicated that you want to iterate through the emails in the Outlook folder "Last week's attachments".
642

Step 5: Iterate through the mail attachments.

  1. Click plus_icon inside the For Each Mail Message activity and then, in the search box at the top of the screen, select the common scenario Iterate through mail attachments.
  2. Browse to and select the In folder and click OK.
    Two activities are added to your project:
    • Save Mail Attachments with Current Mail selected for the From Message field, indicating that the attachments from the current mail in the iteration should be saved to the In folder that is indicated by the C:\In selected in the Save to folder field.
    • For Each File In Folder with C:\In selected in the Folder field to indicate that you will iterate through the files in this folder.
      If you click Start to execute the automation now, the mail attachments are downloaded and saved to the In Folder.
584

Step 6: Rename and move the mail attachments to a different folder.

  1. In the Activities panel, select the Excel tab, then drag the Write Cell activity and drop it inside the For Each File In Folder activity.
  2. In the Write Cell activity:
    • Click plus button on the right side of the What to write field and then select Current File > Full Path to indicate that we want to copy the full path of the current file in the iteration.
    • Click plus button on the right side of the Where to write field and then select Workspace Excel > File [Sheet] > FullFileName [Cell] to indicate that we want to paste the full path of the current file in the iteration to the FullFileName named cell in the File sheet of the Excel Workspace.
  3. Click Open Excel Workspace in the ribbon menu. In the Excel_Workspace file, go to the File sheet, update the value in the named cell ReformattedFileName (B14) to the following: =FileNameNoExtension & "-" & YYYYMMDD & "." & FileExtension and save the file. This formula adds the current date at the end of the file name.
  4. In the Activities panel, select the File tab, then drag the Move File activity and drop it after the Write Cell activity inside For Each File In Folder.
  5. In the Move File activity:
    • Click plus button on the right side of the From field and then select Current File > Full Path to indicate the full path of the current file in the iteration.
    • Click plus button on the right side of the To field and then select Text. In the Text Builder, enter C:\Out\ and then click plus button on the right side of the window and select Workspace Excel > File [Sheet] > ReformattedFileName [Cell]. The path in the Text Builder should look like this: C:\Out\[Excel] File!ReformattedFileName.
    • Make sure the Overwrite option is selected.
  6. Click Save in the Text Builder.
646
  1. Click Save in the ribbon menu to save the automation, then click Run to execute the automation.
    The attachments from each email in the Outlook Search Folder are saved to the In folder on the computer, then today's date is added to the name and they are moved to the Out folder.

Download example

Updated 2 years ago


Tutorial: Saving, Renaming, and Moving Attachments


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.