- 03 Jun 2022
- 4 Minutes to read
- Print
- DarkLight
Downloading Email From a Mail Server [POP]
- Updated on 03 Jun 2022
- 4 Minutes to read
- Print
- DarkLight
Overview
Using the Get Email component, a flow can retrieve messages from a mail server. The flow can display the messages in a form or use them in other ways.
The Get Email component is also available for use with an IMAP mail server.
To enable a flow to download emails from a POP mail server, in the Toolbox panel, in the category Communication > POP, drag a Get Email component to the workspace and configure its properties in the Properties panel.
Example
Our example flow will retrieve one message from our Gmail account and display its body text and headers in a form.
A form to display the email - Form 1 - has already been created for this example.
Begin by navigating to a project folder and clicking the Create Flow button.
On the New Flow dialog to give the flow a name and click CREATE to open it in the Flow Designer.
The first step that we will add to our flow will retrieve a message header.
In the Flow Designer's startup window, under the category, All Steps [Catalog] > Communication > POP, select a Get Headers component and click Add to add the step to the workspace.
To retrieve message headers, Get Headers 1 must be configured with the appropriate settings for the Gmail server. Most of the following settings are specific to the POP protocol. To download messages from a mail server via IMAP, refer to the article on Downloading Email From a Mail Server [IMAP].
Configure Get Headers 1's settings in the Properties panel, in the Inputs section. Because we only want to get one message, in the Count section, enter "1" in the Value field.
To authenticate the connection, enter the password for the email account in the Value fields in the section Password. In the Port section, in the Value field, enter "995". Also, want to ensure that our authentication details are kept secure. In the Secure Connection section, select the Value checkbox.
To make the connection itself, in the Server section, enter "pop.gmail.com" in the Value field.
To authenticate the connection, enter the Username for the email account in the Value field in the section Username.
Once the flow has retrieved a message header, the Get Email component uses the header to retrieve the full message.
In the Steps panel, under Communication > POP, drag a Get Email component to the workspace.
Configure Get Email 1's settings in the Properties panel, in the Inputs section.
To authenticate our connection, enter the password for the email account in the Value field in the section Password. In the Port section, in the Value field, enter "995".
Also, ensure that the authentication details are kept secure. In the Secure Connection section, select the Value checkbox.
To make the connection itself, in the Server section, enter "pop.gmail.com" in the Value field.
In the Unique ID section, select a category by selecting Select Value in the Mapping type drop-down list. To set the path, click the Path selector.
The Get Email step also uses a Unique ID. This field works on the assumption that previous steps may output more than one message header, from which we may only want to get a certain category of message.
In the resulting pop-up, select the path:GetHeaders1_Headers > All UniqueId > First. This path will select the header associated with the first (and, in this example, only) header outputted by Get Headers 1 when all messages are sorted by their unique identifiers.
Once the flow has retrieved a message, it needs to display that message in a form, which already designed.
In theToolbox panel, under the categoryForms [Interaction] > [Current Folder], drag aForm 1 component to the workspace.
Next, map the outcomes of the flow steps.
Get Email 1 offers two possible outcomes - Found and Not Found. If the email account contains no messages, there will be no point in displaying the form, so direct the flow to the End Step. If there is an email message, display it in the form. The form also contains a Done button, and when the user clicks it, the flow will be directed to the End Step. In either circumstance, the user's travel through the flow will be completed.
The last unfulfilled requirement is to make the form display the message details, map the inputs for [Form] Form 1 in the Properties panel, under the section Inputs > Email. In the Mapping type drop-down list, select Build Array, which will allow us to build a list of items for display in the form.
In the Item 0 section, select Select Value in the Mapping type drop-down list, and click the Path selector. Select GetEmail1_Message then select OK.
This completes the flow. It is now ready to save and test in the debugger.
Because the flow interacts with external systems, see the lag time between the flow and Gmail's servers reflected in real-time in the debugger's events and on the Diagram tab. This view is by no means a perfect indicator of network health, but if there was a significant lag between steps, it might be an indicator of a problem worth exploring. The lag-time seen while debugging this example flow is perfectly normal.
The flow works. As required, a form shows that displays the details of a single message downloaded from the Gmail account.