5 min readUpdated Mar 2, 2026

readEmails Logic Documentation

Overview

The readEmails logic serves the purpose of fetching emails from an Outlook Mail account based on specific search criteria. This function allows users to specify filters for their email retrieval, such as the mail folder and search queries, and determines whether to include the complete body of the emails in the output. The resulting data can be used in various analytics or reporting applications, enabling users to effectively manage and analyze their email information.

Settings

1. query

2. folder

3. maxResults

4. includeBody

How It Works

  1. Integration Initialization: The function starts by building a connection instance to the Outlook Mail service using BuildConnectionInstance, passing in the context for authorization.

  2. Input Processing: The function then retrieves the configured inputs or defaults for query, folder, maxResults, and includeBody.

  3. Query Construction: The function formulates a listOptions object, selectively adding query and folder if they've been specified by the user.

  4. Email Retrieval: The function calls the listMessages method of the Outlook Mail integration, passing along the constructed options to fetch the emails.

  5. Result Processing: The function checks if any emails were retrieved. If not, it returns an empty data structure with metadata including the query and folder details. If emails are found, it converts the results into a flat array of simplified row data using OutlookMailIntegration.messageToRow, optionally including the body text based on the setting provided.

  6. Error Handling: Any errors encountered during the connection or fetching process are logged and returned in the response.

Expected Data

The readEmails logic expects:

Use Cases & Examples

Use Case 1: Automated Invoice Processing

In a business environment where invoices are frequently sent via email, the readEmails logic can be deployed to automatically fetch emails matching invoice subjects from a designated invoices folder.

Use Case 2: Customer Service Email Monitoring

Customer service teams can utilize this logic to retrieve emails from a shared inbox folder, tracking customer inquiries by filtering based on specific keywords in their emails.

Concrete Example

Scenario: A users wants to retrieve the latest 50 emails from their "inbox" that contain the subject "Invoice" and include the full body of those emails.

json
{
  "inputs": {
    "query": "subject:Invoice",
    "folder": "inbox",
    "maxResults": 50,
    "includeBody": true
  },
  "config": {}
}

Explanation:

Upon execution, the function would return the matching emails, allowing the user to review or process the invoice information as needed.