Read and Review Automation Anywhere Documentation

Automation 360

Close Contents


Open Contents

Using the For each mail in mail box iterator

  • Updated: 2022/09/28
    • Automation 360 v.x
    • Build
    • RPA Workspace

Using the For each mail in mail box iterator

You must use certain Email actions within a Loop action. Use the For each mail in mail box iterator to repeat a set of actions on all the emails within the specific parameters.


First, connect to the email server. Using the Connect action

When you establish a connection with Microsoft Outlook, email messages are processed from the shared mailbox. Ensure that you have set up the shared mailbox in your Outlook application.
Note: This feature is supported only for Outlook.
You must use the following Email actions within a loop:
  • Change status
  • Delete
  • Save attachments
  • Save email
Emails are retrieved based on the sequence of the folders listed in the inbox field. Within each folder, emails are retrieved based on received date and time in the last in, first out (LIFO) order. Additionally, you can apply filters on the following fields:
  • Types of emails: All, Read, and Unread
  • Subject
  • From a specific folder
  • From specific sender
  • Before, on, or after received date


To use an Email action within a loop, follow these steps:

  1. Double-click or drag the Loop action from the Loop package in the Actions palette.
  2. Select the For each mail in mail box option from the Iterator list.
  3. In the Session name field, enter the name of the session that you used to connect to the email server in the Connect action.
  4. In the ALL, READ, or UNREAD options, specify the type of email to retrieve from the email server.
    Note: For an email server that uses the POP3 protocol, all emails are retrieved.
  5. Optional: Specify the folder from which you want to retrieve the emails.
    • Microsoft Outlook and Yahoo: You can specify the name of the folder.

      For example, Inbox, Sent, Inbox/Sales, Inbox/IT and so on. The Sales and IT folders in this example are user-created folders and not available by default.

    • Gmail:
      • To retrieve emails from the default folders, you must use [Gmail]/FOLDER, except for the Inbox folder.

        For example, [Gmail]/Draft, [Gmail]/Important, [Gmail]/Trash, and so on.

      • To retrieve emails from the folders you have created or the Inbox folder, you must specify the folder names as they are.

        For example, if you have created folders called Bank and Sports in your Gmail, specify Bank and Sports without the [Gmail] prefix to retrieve emails from these folders.

  6. Optional: In the When subject contains field, specify a value to retrieve emails containing the value you specified in their subject.
  7. Optional: In the From specific senders field, specify the email addresses to retrieve the emails.
  8. Optional: In the When received date is on or after list, select an option to retrieve specific emails on or after a certain date.
  9. Optional: In the When received date is on or before list, select an option to retrieve specific emails on or before a certain date.
    If you have specified values for Steps 6 through 9, the system retrieves only those emails that meet all the criteria. For example, if you specify Bank in Step 5, Statement in Step 6, and in Step 7, the system retrieves emails from the Bank folder that contain Statement in the subject and were received from the email address.
  10. Choose one of the following options from Use local timezone
    • True: The email received date and time is displayed in the local time zone.
    • False: The email received date and time is displayed in the UTC time zone.
    • Variable: Enter a Boolean variable.
  11. Optional: In the Assign the current value to variable list, select or create a dictionary variable.

    The dictionary variable stores the properties of each email. Using dictionary variable for email properties.

  12. Click Save.
Insert a Message Box action into the Loop container to print the subject of each email. Use the following message body, substituting the generic variable name for the one you used in Step 10: $dictionaryVar{emailSubject}$
Send Feedback