Example using Email actions in a bot

In this example, we use email actions to perform email-related operations using Outlook Client.

Create a bot to perform the following tasks:
  • 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

  1. Create a bot.
    1. On the left panel, click Automation.
      A list of available bots and forms is displayed.
    2. Click Create New > Bot.
    3. Provide a name for the bot: Email_Operation_Bot.
    4. Click Create and Edit.
  2. Use the Connect action to establish a connection with an email server.
    1. Double-click or drag the Email > Connect action.
    2. Enter EmailSession in the Session name field.
    3. Select Outlook to establish a connection with Microsoft Outlook.
    4. Enter test@automationanywhere.com in the Outlook mailbox (optional) field.
  3. To process each item in the email, use the Loop action.
    1. Double-click or drag the Loop action.
    2. Select For each mail in mail box from the iterator list.
    3. In the Session name field, enter EmailSession.
    4. Select All from the Type of emails to get field to retrieve emails from the email server.
    5. In the From a specific folder (optional) field, enter Inbox/Analytics folder.
    6. Choose HTML option for message format.
    7. Select True from the Use local timezone list.
    8. In the Assign the current value to variable (optional) field, create EmailDetails as a Dictionary variable.
  4. Retrieve the total number of attachments from each mail and print.
    1. double-click or drag the Message box action
    2. In the Enter the message to display field, enter: $EmailDetails{emailSubject}$EmailDetails{emailNoOfAttachments}$
  5. Double-click or drag the Email > Disconnect action. In the Session name field, enter EmailSession.
  6. Click Save and then Run.
    The attachment details are retrieved from the emails as follows:

    Use of email dictionary property (no of attachments)

    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
  7. Start a new Email session.
    1. Double-click or drag the Email > Connect action.
    2. Enter EmailSession1 in the Session name field.
    3. Select Outlook to establish a connection with Microsoft Outlook.
    4. Enter test@automationanywhere.com in the Outlook mailbox (optional) field.
  8. To process each item in the email, use the Loop action.
    1. Double-click or drag the Loop action.
    2. Select For each mail in mail box from the iterator list.
    3. In the Session name field, enter EmailSession1.
    4. Select All from the Type of emails to get field to retrieve emails from the email server.
    5. In the From a specific folder (optional) field, enter Inbox/Daily stand up meeting.
    6. Choose HTML option for message format.
    7. Select True from the Use local timezone list.
  9. Use the Reply All action to send a response to an email.
    1. 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.
    2. In the Subject (optional) field, enter Documentation deliverables for upcoming releases.
    3. Add the file attachment to the email message release plan.xlsx.
    4. Select Plain text for the email body.
    5. In the Message field, enter the following message as follows:
      Hi All,
      See the attached document outlining the release plan.
    6. Select the Outlook option from the Send email via list.
  10. Double-click or drag the Email > Disconnect action. In the Session name field, enter EmailSession1.
  11. Click Save and then Run
    The response will be sent to the sender and all the recipients of an email.
  12. Start a new Email session.
    1. Double-click or drag the Email > Connect action.
    2. Enter EmailSession2 in the Session name field.
    3. Select Outlook to establish a connection with Microsoft Outlook.
    4. Enter test@automationanywhere.com in the Outlook mailbox (optional) field.
  13. Use the Delete All action to delete all the email from the inbox.
    1. Enter EmailSession2 in the Session name field.
    2. In the From a specific folder (optional) field, enter Inbox/Backup mails.
    3. Select All from the Type of emails to get field to retrieve emails from the email server.
  14. Double-click or drag the Email > Disconnect action. In the Session name field, enter EmailSession2.
  15. Click Save and then Run.
    The emails will be deleted from the specified folder.