Description
The main difference between "For Each Email" and "Read emails" is
"Read emails" stores all emails in one variable, for example email_messages
. However, "For Each Email" does not store all emails and works with one email at a time. In the case of the "For Each Email" activity, the bot also reads all e-mails according to the filters at once.
This activity allows you to apply a set of actions to each email for the selected account. Unlike other activities, it has a specific structure, when you add this activity to a workflow, a gray area appears. The area contains the body of the loop — the set of actions you would like to apply to each email in your email box. Firstly, you need to drag and drop desired activities here, link them to the "For Each Email" block, and then to the "Loop end" block. The activity looks like as shown below.
A template of the "For Each Email" activity.
How to work with credentials
To start using this activity, you first need to enter the credentials for your email box.
The button to add new credentials.
This article describes in detail the process of adding credentials.
Parameters
Host and email
Click on the drop-down list to select the required host/login pair. Then start typing your host or login name so that this pair (email address) appears at the top of the list.
Server settings
This option allows you to specify the settings of the server used for e-mail messages.
- Custom: allows you to manually select the protocol "IMAP" or "POP3", enter the server address in the "Server address" field and select a secure connection.
- Secure connection - if this checkbox is checked, then the connection will be performed using TLS.
- Yandex: the default settings for the Yandex server are applied.
- Google: The default settings for the Google server are applied.
- Yahoo: The default settings for the Yahoo server are applied.
- Mail.ru: Mail.ru default settings are applied.
- iCloud: The default settings of the "iCloud" server are applied.
Date from
If there is no value for the “Date from” parameter, emails from the last 24 hours will be read.
- Set a value: allows you to explicitly specify the date from which the mail messages are to be read. If you click in the corresponding field, the calendar will pop up, in which you can manually select the desired date.
- Calculate a value: allows you to use a special formula or a special method to specify the date from which the messages are to be read.
- Save the previous step result: takes the result of the function from the previous workflow action as the date.
Filter by status
Unread only
Read the emails with the "Unread" status only.
Starred only
Read the emails marked as "Important" only.
From a specific category (Gmail)
Read the emails from the category you specified.
Filter by content
Subject contains
Retrieve emails with a specific subject.
- Set a value: allows you to manually write a keyword for the subject of an email.
- Calculate a value: allows you to use a special formula or a special method to specify a keyword.
- Save the previous step result: takes the result of the action from the previous workflow step as the keyword.
Body contains
Retrieve emails that contain a certain value in the body (text) of the email.
- Set a value: allows you to manually set a keyword for the body of the letter.
- Save the previous step result: takes the result of the action from the previous workflow step as the keyword.
- Calculate a value: allows you to use a special formula or a special method to specify a keyword.
Sender
Retrieve emails that came from a specific sender.
- Set a value: allows you to manually specify the sender of an email.
- Calculate a value: allows you to use a special formula or a special method to specify the sender.
- Save result of previous step: takes the name of the sender from the result of the previous step in the workflow.
Attachments
Download attachments
Allows you to download the attachments from all read emails for a specified period.
Directory path template
The option is available only if the Download attachments option is selected. It requires you to specify the folder where the files will be uploaded. It is also possible to specify {{keyword}}
in the path to save the attachments, where keyword
is one of the parameters listed below:
from
- sender;to
- the recipient;cc
- those specified in the copy;date
- date the message was sent;messageId
- unique identifier of the message;dateTime
- date time in the ISO format;dateTimeMs
- date and time in the Unix time format;receivedDateTime
- date and time of receiving the message in the ISO format;receivedDateTimeMs
- date and time of sending in the Unix time format.
When keywords are added, the bot will automatically create sub-folders with the date or subject of the corresponding message. You can specify several keywords.
- Set a value: allows you to explicitly specify the path to the folder, for example,
C:\ElectroNeek\
orC:\ElectroNeek\{{date}}\{{subject}}
. - Calculate a value: allows you to use a special formula or a special method to form a folder.
- Save the previous step result: takes the result of the function from the previous workflow action as a folder.
Mail folder name
If you want to read mails from a subfolder, the path must be specified with |
. For example, there is an "Inbox" folder with a subfolder called "Work". The path to the "Work" folder should be set in the following way: Inbox|Work
.
- Set a value: allows you to specify explicitly the path to the folder from which you want to read the mail messages.
- Calculate a value: allows you to use a special formula or a special method for specifying a folder name.
- Save the previous step result: takes the folder name from the result of the previous step in the workflow.
Emails limit
This parameter allows you to set the number of emails to be read.
Load one by one
This new parameter allows you to create bots that can interact with emails one by one and get partial results while handling many emails at a time. If you enable this checkbox, the bot can:
-
-
read the first email;
-
process it;
-
read the second email;
-
process it; and so on.
-
For example, if you have a bot that reads several emails and downloads files per each email, with this parameter the bot will download each file while running, so you will have them available before the workflow finishes.
Comment
This parameter allows you to create an annotation for the activity. The input text will be displayed above the activity name.
How to use it?
"For Each Email" is a better option for dealing with a high volume of emails than "Read emails". As "For Each Email" does not store all emails in your memory and only works with one email at a time.
Since there are many ways to use this activity, let us look at the following example to understand a simple workflow.
An example of a workflow.
In this test case, we would like to display the text of each email from our email box in the console log using "Console log". Therefore, we need to use the correct key, in this case "text" as follows
The result of this workflow should look like below.