Overview

Sections

How to create an RPA flow using email activities to read emails and save attachments

Note: Email exchange activities are no longer supported; RPA developers should use either the Outlook Mail Graph activities or Outlook Mail as is done here.

This page currently exists as an archive.

Intermediate | 25 Minutes

RPA

Overview

This tutorial will show you how to create a basic flow using RPA mail automation activities to read emails and store attachments. We will build an RPA flow that first reads emails from an account and then saves the attachments for each email.

Scenario

You need to read emails and save attachments, but your email application is not stored on your local desktop.

📋 Requirements

  • This specific flow should be used when the Outlook application is not installed on the machine, either for attended or unattended flow. Currently, this flow cannot be used from the Infor domain account due to security configurations.
  • Before you can start building the flow, you’ll need to install RPA Studio on your machine and set up a connection between RPA Studio and RPA Management.
  • You may also need to create a few artifacts:
  • Create a folder to store the attachments: C:\RPA\Attachments

Resources

Download the project for reading Outlook files and saving the attachments:

ReadOutlookAndSaveAttachments

Note: Email exchange activities are no longer supported; RPA developers should use either the Outlook Mail graph activities or Outlook Mail.

Tutorial

1

Create a New Project in RPA Studio

  • Open RPA Studio on your machine. If you're not already signed in to the tenant, you'll be prompted to sign in.
  • On the Home page of RPA Studio, click Create New Project and specify the following properties in the pop-up window:
  • Name: MailAttachmentFlow
  • Project Location: <default>
  • Description: Save the attachments from a mail
  • Language: VB (selected by default)
2

Setting Up the Email Server

  • Add the Email Server Setup activity and specify the following properties:
  • Email Address: This is the mail server you want to access. Specify the argument:
    • Called: _mailaccount_ of type string with a default value of your mail account.
  • Password: This is the password for your mail server account. Specify the argument:
    • Called: _password_ of type string with the default value for your account password.
  • Email Server: This stores the server details such as email and password. Specify the variable:
    • Called: _server_ of type ExchangeService (Microsoft.Exchange.WebServices.Data.ExchangeService).
    • To find ExchangeService, expand the Variable Type and select Browse for type. In the Type Name cell, type ExchangeService and select Exchange Server under the Microsoft.Exchange.WebServices.Data domain.

3

Read Emails Activity

  • Add the Read Emails activity and specify the following properties:
  • Email Server: Use the variable from the output of the Email Server Setup activity. Specify the _server_ variable.
  • Optionally, you can specify:
    • Number of Emails to Read
    • Sender Filter
    • Subject Filter
    • Unread Only
  • Emails: This is the output variable that will store the emails read from the server. Specify the variable:
    • _emails_ of type List (System.Collection.Generic.List<Microsoft.Exchange.WebServices.Data.EmailMessage>).
    • To find List, expand the Variable Type and select Browse for type. In the Type Name cell, type List and select List under the System.Collection.Generic domain. Once selected, under System.Collection.Generic.List, select Browse for type again, and in the Type Name cell, type EmailMessage and select EmailMessage under Microsoft.Exchange.WebServices.Data.

4

For Each Activity (Looping through Emails)

  • Add the For Each activity and specify the following properties:
  • Type: Set this to EmailMessage (Microsoft.Exchange.WebServices.Data.EmailMessage)—this matches the type of a single object from the _emails_ variable.
  • Value: Define this as _emails_.
  • In the activity on the design canvas, you will see the text: “For Each item in _emails”. The item refers to a single email within the list of emails.

We need to specify the activity for reading the mail, for that we need to add Read Emails activity and specify the following properties:

  • Email Server which is the variable which points to the output of Email Server Setup activity. Specify here sever variable.
  • Optionally you can specify:
  • Number of Emails Read
  • Sender Filter
  • Subject Filter
  • Unread Only
  • Emails its output value will store the emails read from the server. Specify the variable:
  • emails of type List<EmailMessage> ( System.Collection.Generic.List< Microsoft.Exchange.WebServices.Data.EmailMessage>
    • To find the List <EmailMessage> data type, expand the Variable Type and select Browse for type. In the Type Name cell type List and select List under the System.Collection.Generic domain. Once selected, below the System.Collection.Generic.List from the dropdown select Browse for type and in the new dialog window in the Type Name cell type EmailMessage and select EmailMessage under Microsoft.Exchange.WebServices.Data

5

Save Attachments Activity

Later we will create a loop which will allow us to save an attachment from each read mail. For that we need to add For Each activity and specify the following:

  • for Type property as EmailMessgae ( Microsoft.Exchange.WebServices.Data.EmailMessage) which is same as a single object type from the emails variable
  • for value property define emails.
  • In the activity on Design Canvas, you will see the following text “Foreach item in emails” the item signify the single object in this example mail within the list of object, here list of mails

6

Run the Flow

Within the Body add Save Attachments activity which will allow us to save the attachment from each of the read mails. Specify the following properties:

  • For Email property specify Item as in For Each activity
  • For Path which is a path of the directory where the attachment should be stored, create variable:
  • called attachementpath of type string and default value “C:\RPA\Attachements”
  • For Attachments output property create a variable
  • called savedfiles of type List <String>
    • To find the List <String> data type, expand the Variable Type and select Browse for type. In the Type name cell type List and select List under the System.Collection.Generic domain. Once selected, below the System.Collection.Generic.List from the dropdown select the String and click ok.

Now we can run this flow to see if all if working as expected. In case of any errors check the Output panel to see where the error may have occurred.

Was this section helpful?

What made this section unhelpful for you?

On this page
  • How to create an RPA flow using email activities to read emails and save attachments
View as Markdown

Ask an AI

Open in ChatGPTOpen in Claude