Search

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

Business Problem

This tutorial will show you how to create a basic flow using RPA mail automation activities to read mail and store attachments. We will build an RPA flow which first reads mails from an account, after which the attachments will be saved for each mail.

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


Components

  • RPA Management
  • RPA Studio

Requirements

  • This specific flow should be used while 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 the RPA Studio and RPA Management.
  • You may also need to create a few artifacts:
    • Create a folder to store the attachments “C:\RPA\Attachments”

Tutorial

1 – Open RPA Studio on your machine. If you are not signed in already into the tenant, you would be asked to sign in before proceeding to RPA flow designer screens.

2 – On the Home page of RPA Studio click Create New Project and specify the following properties in the pop-up window:

(a) Name: MailAttachementFlow

(b) Project Location: <default>

(c) Description: Save the attachments from a mail

(d) Language: VB <selected by default>

3 – Let’s first focus on setting up the mail sever. For that we need Email Server Setup activity and specify the following properties:

  • Email Address – which is the mail server we would like to access. Specify the argument:
    • called: mailaccount of type string and default value for your mail account.
  • Password – which is the password to you mail server accounts. This is a protected value; you should specify the argument and used its name within the field value. You can also type the password directly into this field yet once published you won’t be able to change it.
    • called: password of type string and default value for your account password.
  • Email Server – which is the value which will be storing the sever details such as e-mail and password. Specify the variable:
    • called: server of type ExchangeService (Microsoft.Exchange.WebServices.Data.ExchangeService)
      • to find ExchangeService data type 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.

4 – Next, 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 – 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 – 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.