Example using Email actions in a bot
- Updated: 2023/03/06
Example using Email actions in a bot
In this example, we use email actions to perform email-related operations using Outlook Client.
- Retrieve the total number of attachments from emails and print the result in the message box.
- Send a response to the sender and all the recipients of an email with the different subject.
- Delete and remove read emails from the Inbox.
Procedure
-
Create a bot.
-
On the left panel, click Automation.
A list of available bots and forms is displayed.
- Click Create New > Bot.
- Provide a name for the bot: Email_Operation_Bot.
- Click Create and Edit.
-
On the left panel, click Automation.
-
Use the Connect action to establish a connection with an email server.
- Double-click or drag the Email > Connect action.
- Enter EmailSession in the Session name field.
- Select Outlook to establish a connection with Microsoft Outlook.
- Enter test@automationanywhere.com in the Outlook mailbox (optional) field.
-
To process each item in the email, use the Loop
action.
- Double-click or drag the Loop action.
- Select For each mail in mail box from the iterator list.
- In the Session name field, enter EmailSession.
- Select All from the Type of emails to get field to retrieve emails from the email server.
- In the From a specific folder (optional) field, enter Inbox/Analytics folder.
- Choose HTML option for message format.
- Select True from the Use local timezone list.
- In the Assign the current value to variable (optional) field, create EmailDetails as a Dictionary variable.
-
Retrieve the total number of attachments from each mail and print.
- double-click or drag the Message box action
- In the Enter the message to display field, enter: $EmailDetails{emailSubject}$EmailDetails{emailNoOfAttachments}$
- Double-click or drag the Email > Disconnect action. In the Session name field, enter EmailSession.
-
Click Save and then Run.
The attachment details are retrieved from the emails as follows:
emailSubject emailNoOfattachments Google Analytics Report for Dec 2022 12 Google Analytics Report for Nov 2022 11 Google Analytics Report for Oct 2022 9 Google Analytics Report for Aug 2022 10 Google Analytics Report for July 2022 13 Google Analytics Report for May 2022 11 Google Analytics Report for March 2022 5 -
Start a new Email session.
- Double-click or drag the Email > Connect action.
- Enter EmailSession1 in the Session name field.
- Select Outlook to establish a connection with Microsoft Outlook.
- Enter test@automationanywhere.com in the Outlook mailbox (optional) field.
-
To process each item in the email, use the Loop
action.
- Double-click or drag the Loop action.
- Select For each mail in mail box from the iterator list.
- In the Session name field, enter EmailSession1.
- Select All from the Type of emails to get field to retrieve emails from the email server.
- In the From a specific folder (optional) field, enter Inbox/Daily stand up meeting.
- Choose HTML option for message format.
- Select True from the Use local timezone list.
-
Use the Reply All
action to send a response to an email.
-
Enter the following email IDs. peter_wilson@example.com,
john.smith@example.com, nancy.mark@example.com
Note: Use comma to separate the emails IDs.
- In the Subject (optional) field, enter Documentation deliverables for upcoming releases.
- Add the file attachment to the email message release plan.xlsx.
- Select Plain text for the email body.
-
In the Message field, enter the following
message as follows:
Hi All, See the attached document outlining the release plan.
- Select the Outlook option from the Send email via list.
-
Enter the following email IDs. peter_wilson@example.com,
john.smith@example.com, nancy.mark@example.com
- Double-click or drag the Email > Disconnect action. In the Session name field, enter EmailSession1.
-
Click Save and then Run
The response will be sent to the sender and all the recipients of an email.
-
Start a new Email session.
- Double-click or drag the Email > Connect action.
- Enter EmailSession2 in the Session name field.
- Select Outlook to establish a connection with Microsoft Outlook.
- Enter test@automationanywhere.com in the Outlook mailbox (optional) field.
-
Use the Delete All
action to delete all the email from the inbox.
- Enter EmailSession2 in the Session name field.
- In the From a specific folder (optional) field, enter Inbox/Backup mails.
- Select All from the Type of emails to get field to retrieve emails from the email server.
- Double-click or drag the Email > Disconnect action. In the Session name field, enter EmailSession2.
-
Click Save and then Run.
The emails will be deleted from the specified folder.