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
- Drag and drop the
Imap/Smtp connectionactivity under theMailcomponent 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 |
-
Provide the configuration for both protocols to perform email operations.
-
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.
- In the
Data Objectfield, define a variable namedpasswordand use it in the password fields.
INFO: Write the variable name between curly braces after a dollar sign (e.g., ${variableName}).
- Find the date three days before today using the
Script taskactivity.
INFO: This date will be used as the minimum date in the Mail search activity.
-
Drag and drop the
Script taskactivity under theActivitiescomponent and use JavaScript to find the date. -
Assign the current date to the
threeDaysAgovariable using theNew Datefunction.
INFO: The current date is assigned in the format year-month-day.
-
Update this variable to represent the date three days ago.
-
Convert this variable to string format using the
toLocaleDateStringfunction. -
Concatenate them by adding a dot between them. Save this variable using the
execution.setVariablefunction to use it as a minimum date.
INFO: The minDate variable will be used to find emails less than 3 days old.
- 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 |
-
Use the
Searchactivity under theMailcomponent. -
In the
Connection namefield, select the connection reference name defined in the first activity from the list. -
Find emails with the subject containing the phrase "Flight Routes" and an attached file. To do this, enter "Flight Routes" in the
Subjectfield and check theHas attachmentbox. -
Do not change the default value of
INBOXin theFolder namefield to ensure the search is performed in the Inbox. -
Select the
Unreadbox to search for unread emails, and define a variable in theDatasetfield to assign all email data to a dataset. -
Set the email search limit to
10in theSearch limitfield. This ensures that even if more than 10 emails match the criteria, only the 10 most recent emails will be imported into the dataset. -
Leave the
Fromparameter blank. This field allows you to filter emails by sender.
Mail > Search
| 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.
-
Find the number of emails transferred to the dataset using the
Get sizeactivity under theDatasetcomponent. -
Choose the
ROWoption in theSize typefield from the list.
Dataset > Get size
| Name | Get size : Request count |
| *Dataset name | ${emailSearchDS} |
| Size type | ROW |
| *Result variable name | emailSearchDSSize |
-
Terminate the process if no emails are found; otherwise, continue if at least one email exists.
-
To achieve this, use a gateway to control the process flow based on defined conditions.
-
For each arrow leaving the gateway, set a condition expression based on the email count variable.
-
If the variable's value is
0, end the process flow. Otherwise, choose thedefault flowoption and do not set any condition expression. -
The process will continue from here if no condition is matched.
| Flow condition | (${emailSearchDSSize==0}) |
-
If the process does not end, continue with a loop activity, as operations will be performed independently for each email.
-
Include the
Sub-processactivity from theStructuresection to create a loop activity in the process. -
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
Cardinalityfield. -
If this definition is not made, the sub-process will run once.
-
In this example, to loop as many times as the number of matching emails, enter the variable holding the email count in the
Cardinalityfield (e.g.,${variableName}). -
Choose
Sequentialfor theMulti-instance typefield, as you want each operation in the loop to be performed sequentially. -
The
loopCountervariable 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} |
-
In the
Read/Save/Attachmentactivity, after selecting thetestConconnection name from the list in theConnection namefield, enter theloopCountervariable in theMail nofield. This ensures emails are processed one by one. -
To archive attached files, check the
Save attachmentsbox and enter the desired directory path in theSave pathfield. -
Select the
Mark as readoption to ensure emails are marked as read. -
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 |