# Tutorial: Iterating Through Outlook Mails and Saving 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.

In this tutorial, we will create an automation that saves the attachments to all the emails in an Outlook Search Folder to your computer.

We will create a project and start by adding a [Use Desktop Outlook App](https://docs.uipath.com/activities/docs/outlook-application-card) activity to indicate the Outlook account to use. In this activity, we will add a [For Each Email](https://docs.uipath.com/activities/docs/for-each-email-x) activity to indicate that we want to iterate through the emails in a folder. We will then add the activities to repeat inside For Each Email.

1. Create a Temp folder on your computer and a Search Folder in Outlook.
   1. Create a folder named **Temp** 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.
2. Set up the project.

   [Create a new blank project using the default settings](https://docs.uipath.com/studiox/standalone/2023.10/user-guide/creating-your-first-automation-project).
3. Add the Outlook account to the project.
   1. In the Activities panel, select the **Mail** tab and then double-click **Use Desktop Outlook App**. The activity is added to the Designer panel.
   2. In the activity, the default email account is already selected in the **Account** field. If you want to use a different account, select it from the drop-down menu.

      In the **Reference as** field, leave the default value `Outlook` as the name by which to refer to the account in the automation.
4. Iterate through the messages in the Outlook folder.
   1. In the Activities panel, drag the **For Each Email** activity and drop it inside the Use Desktop Outlook App activity.
   2. In the **For Each Email** activity, click **Plus** ![docs image](https://dev-assets.cms.uipath.com/assets/images/studiox/studiox-image-plus_menu-90e71eaa-8a20ac7d.png) on the right side of the **In emails from** field, and then select **Outlook** > **[Search Folders]** > **[Last week's attachments]** to select the search folder created in the account `Outlook`. Your selection is displayed in the **In emails from** field as `Last week's attachments`.

      You have indicated that you want to iterate through the emails in the Outlook Search Folder Last week's attachments.

      ![docs image](https://dev-assets.cms.uipath.com/assets/images/studiox/studiox-docs-image-350562-3d4df9ab-370747c7.webp)
5. Save the attachments for each message to a folder on your computer.
   1. In the Activities panel, drag the [Save Email Attachments](https://docs.uipath.com/activities/docs/save-mail-attachments-x) activity and drop it inside the **For Each Email** activity.
   2. In the Save Email Attachments activity:
      * Click **Plus** ![docs image](https://dev-assets.cms.uipath.com/assets/images/studiox/studiox-image-plus_menu-90e71eaa-8a20ac7d.png) on the right side of the **Email** field, and then select **CurrentMail** to indicate that the email whose attachments you want to save is the current email you are iterating through.
      * Click **Browse** ![docs image](https://dev-assets.cms.uipath.com/assets/images/studiox/studiox-docs-image-browse_files-3f5ed0c5-1431ef7d.png) next to the **Save to folder** field, and then browse to and select the folder on your computer where to save the attachments. For this example, we created a folder called `Temp` on the C drive of the computer.

        ![docs image](https://dev-assets.cms.uipath.com/assets/images/studiox/studiox-docs-image-350566-d9832297-15faa841.webp)
   3. Click **Save** in the StudioX ribbon to save the automation, then click **Run** to execute the automation.

      The attachments from each email in the Outlook folder Temp are saved to the Temp folder on the computer.[Download example](https://documentationexamplerepo.blob.core.windows.net/examples/StudioX_V2022.10/OutlookIterateThroughMails.zip)
