Skip to content

How to design a sample process that includes e-mail operations with Robusta RPA tool step by step?

PROCESS SCENARIO

In this tutorial:

  • Connect to an email account and search for unread emails with a specific subject and an attached file.
  • Forward each matching email that meets certain conditions to another email account.
  • For the emails which do not meet the condition, reply to the sender that the request is invalid.

STEP BY STEP PROCESS

  1. Drag and drop the Imap/Smtp connection activity under the Mail component to connect to an email account.

INFO: While SMTP protocol is used for sending email, IMAP protocol is used for email reading.

Mail > Imap/Smtp connection

Name Imap/Smtp connection : Connect to E-mail account
Configuration name connectionName
*Connection name testCon
*Imap host imap.gmail.com
*Imap port 993
*Imap user E-mail address for IMAP protocol.
*Imap password ${password}
Imap ssl True
*Smtp host smtp.gmail.com
*Smtp port 587
*Smtp user E-mail address for SMTP protocol.
*Smtp password ${password}
Smtp tls enabled True
Smtp tls required True
  1. Provide the configuration for both protocols to perform email operations.

  2. To connect to a Gmail account, refer to the relevant Google support page: https://support.google.com/mail/answer/7126229?hl#zippy=%2Cstep-change-smtp-other-settings-in-your-email-client

INFO: The Data Object allows you to define a variable and use it in any activity within the process. Click any area in the process design area to open the Data Object field.

  1. In the Data Object field, define a variable named password and use it in the password fields.

INFO: Write the variable name between curly braces after a dollar sign (e.g., ${variableName}).

  1. Find the date three days before today using the Script task activity.

INFO: This date will be used as the minimum date in the Mail search activity.

  1. Drag and drop the Script task activity under the Activities component and use JavaScript to find the date.

  2. Assign the current date to the threeDaysAgo variable using the New Date function.

INFO: The current date is assigned in the format year-month-day.

  1. Update this variable to represent the date three days ago.

  2. Convert this variable to string format using the toLocaleDateString function.

  3. Concatenate them by adding a dot between them. Save this variable using the execution.setVariable function to use it as a minimum date.

INFO: The minDate variable will be used to find emails less than 3 days old.

  1. Write the variable name between curly braces after a dollar sign (e.g., ${variableName}).

Activities> Script task

Script format javascript
Script var threeDaysAgo = new Date(); threeDaysAgo.setDate(threeDaysAgo.getDate()-3); var date = threeDaysAgo.toLocaleDateString(); var splitDate = date.split(“-“); var year = splitDate[0]; var month = splitDate[1]; var day = splitDate[2]; var minDate = day+”.”+month+”.”+year; execution.setVariable(“minDate”, minDate);
Name Script task : Find three days ago
Exclusive True
  1. Use the Search activity under the Mail component.

  2. In the Connection name field, select the connection reference name defined in the first activity from the list.

  3. Find emails with the subject containing the phrase "Flight Routes" and an attached file. To do this, enter "Flight Routes" in the Subject field and check the Has attachment box.

  4. Do not change the default value of INBOX in the Folder name field to ensure the search is performed in the Inbox.

  5. Select the Unread box to search for unread emails, and define a variable in the Dataset field to assign all email data to a dataset.

  6. Set the email search limit to 10 in the Search limit field. This ensures that even if more than 10 emails match the criteria, only the 10 most recent emails will be imported into the dataset.

  7. Leave the From parameter blank. This field allows you to filter emails by sender.

Name Search : E-mails for flight routes price request
*Connection name ${testCon}
*Folder name INBOX
Has attachment? True
Search limit 10
Min date ${minDate}
Subject Flight Routes
Unread True
*New dataset name emailSearchDS

INFO: To view the dataset, open an Excel file containing the data resulting from this activity. This data includes information such as subject, sender's email, and mail body.

  1. Find the number of emails transferred to the dataset using the Get size activity under the Dataset component.

  2. Choose the ROW option in the Size type field from the list.

Dataset > Get size

Name Get size : Request count
*Dataset name ${emailSearchDS}
Size type ROW
*Result variable name emailSearchDSSize
  1. Terminate the process if no emails are found; otherwise, continue if at least one email exists.

  2. To achieve this, use a gateway to control the process flow based on defined conditions.

  3. For each arrow leaving the gateway, set a condition expression based on the email count variable.

  4. If the variable's value is 0, end the process flow. Otherwise, choose the default flow option and do not set any condition expression.

  5. The process will continue from here if no condition is matched.

Flow condition (${emailSearchDSSize==0})
  1. If the process does not end, continue with a loop activity, as operations will be performed independently for each email.

  2. Include the Sub-process activity from the Structure section to create a loop activity in the process.

  3. As in the main process, create a flow with a beginning and end event within this sub-process. Define how many times this sub-process will repeat in the Cardinality field.

  4. If this definition is not made, the sub-process will run once.

  5. In this example, to loop as many times as the number of matching emails, enter the variable holding the email count in the Cardinality field (e.g., ${variableName}).

  6. Choose Sequential for the Multi-instance type field, as you want each operation in the loop to be performed sequentially.

  7. The loopCounter variable is automatically defined at the beginning of the loop.

INFO: loopCounter starts at 0 and increases by 1 at each iteration. The loop automatically terminates when loopCounter reaches the Cardinality value.

Structural> Sub process

Name Loop for each e-mail request
Exclusive True
Multi-instance type Sequential
Cardinality (Multi-instance) ${emailSearchDSSize}
  1. In the Read/Save/Attachment activity, after selecting the testCon connection name from the list in the Connection name field, enter the loopCounter variable in the Mail no field. This ensures emails are processed one by one.

  2. To archive attached files, check the Save attachments box and enter the desired directory path in the Save path field.

  3. Select the Mark as read option to ensure emails are marked as read.

  4. This prevents the process from repeatedly processing the same emails. Import the list of attached files into a dataset.

Mail > Read/Save/Attachment

Name Read/Save/Attachment : Dowload to ‘archieve’ folder
*Connection name ${testCon}
*Dataset name emailSearchDS
Mail no ${loopCounter}
Mark as read? True
Save attachments? True
Save path The location you want to save the files.
Attachment database name `Attachment