Skip to content
Skip to main content

Get Exchange email threads with Nylas

Last updated:

Exchange on-premises servers support conversation grouping through a ConversationId property that EWS assigns to each message. Nylas maps this directly to the Threads API, giving you a conversation view for self-hosted Exchange accounts through the same endpoint you’d use for Gmail or Outlook online.

This guide covers listing threads from Exchange on-prem accounts and the EWS-specific details: when to use EWS vs. Microsoft Graph, how ConversationId maps to threads, message ID behavior, and search limitations.

How do I list Exchange email threads with the Nylas API?

Section titled “How do I list Exchange email threads with the Nylas API?”

Send a GET request to /v3/grants/{grant_id}/threads with your API key. The endpoint returns the most recent threads by default and up to 200 per page, each with a latest_draft_or_message object. Exchange groups messages using its native conversation tracking. The same call works across Gmail, Outlook, and IMAP. See List threads for the request and response.

This is the first thing to figure out. The two provider types target different Exchange deployments:

Provider typeConnectorUse when
Microsoft GraphmicrosoftExchange Online, Microsoft 365, Office 365, Outlook.com, personal Microsoft accounts
Exchange Web ServicesewsSelf-hosted Exchange servers (on-premises)

If the user’s mailbox is hosted by Microsoft in the cloud, use the Microsoft thread guide instead. The ews connector is specifically for organizations that run their own Exchange servers.

Why use Nylas for threads instead of EWS directly?

Section titled “Why use Nylas for threads instead of EWS directly?”

EWS is a SOAP-based XML API. Building a conversation view requires constructing XML SOAP envelopes for FindConversation operations, parsing nested XML responses, handling EWS-specific ConversationId and ConversationIndex fields, and managing autodiscovery to find the right server endpoint. Error responses come back as SOAP faults with nested XML structures.

Nylas replaces all of that with a JSON REST API. The /threads endpoint returns pre-grouped conversations with metadata. No XML, no WSDL, no SOAP. Authentication and autodiscovery are handled automatically.

You’ll need:

  • A Nylas application with a valid API key
  • A grant for an Exchange on-premises account
  • An EWS connector configured with the ews.messages scope
  • The Exchange server accessible from outside the corporate network (not behind a VPN or firewall that blocks external access)

Create an EWS connector with the scopes your app needs:

ScopeAccess
ews.messagesEmail API (messages, threads, drafts, folders)
ews.calendarsCalendar API
ews.contactsContacts API

During authentication, users sign in with their Exchange credentials, typically the same username and password they use for Windows login. The username format is usually [email protected] or DOMAIN\username.

The full setup walkthrough is in the Exchange on-premises provider guide.

The Exchange server must be accessible from Nylas’s infrastructure:

  • EWS must be enabled on the server and exposed outside the corporate network
  • If the server is behind a firewall, you’ll need to allow Nylas’s static IP addresses. Static IP routing requires an annual contract. Contact sales to upgrade your plan

Accounts in admin groups are not supported.

Make a List Threads request with the grant ID. By default, Nylas returns the most recent threads. These examples limit results to 5:

The response includes a latest_draft_or_message object with the most recent message’s content. The same code works for Google, Yahoo, and IMAP accounts.

Exchange on-premises assigns every message a ConversationId, so threading is native rather than reconstructed. The Nylas CLI maps that straight through: nylas email threads list returns each Exchange conversation as one row, with no XML or SOAP on your side.

The Nylas CLI groups messages into conversations the same way the Threads API does. After nylas init and nylas auth login, email threads list returns the 10 most recent threads by default, each collapsing a full back-and-forth into a single row:

# List the 10 most recent threads
nylas email threads list
# Only unread threads, filtered by subject
nylas email threads list --unread --subject "invoice"
# Open one thread to see every message in the conversation
nylas email threads show <thread-id>

Thread search works differently from message search: it filters by field rather than free text, so you match on --subject, --from, or --unread instead of passing a bare query string:

# Find threads by subject and sender
nylas email threads search --subject "contract renewal" --from "[email protected]"

Both commands accept --json for scripting. See the email threads list and email threads search command reference for every flag.

Because the server tracks conversations itself, EWS threading stays stable as messages move between folders. The Threads API returns up to 200 threads per page, and nylas email threads show expands any conversation into its messages.

You can narrow results with query parameters. Here’s what works with Exchange accounts:

ParameterWhat it doesExample
subjectMatch on subject line?subject=Weekly standup
fromFilter by sender[email protected]
toFilter by recipient[email protected]
unreadUnread only?unread=true
inFilter by folder or label ID?in=INBOX
received_afterAfter a Unix timestamp?received_after=1706000000
received_beforeBefore a Unix timestamp?received_before=1706100000
has_attachmentOnly results with attachments?has_attachment=true

Here’s how to combine filters. This pulls threads with unread messages from a specific sender:

Exchange supports the search_query_native parameter using Microsoft’s Advanced Query Syntax (AQS). You can combine search_query_native with any query parameter except thread_id.

The Exchange server must have the AQS parser enabled and search indexing active for search_query_native to work. If queries aren’t returning expected results, the Exchange admin should verify these settings.

See the search best practices guide for more on search_query_native across providers.

Exchange on-prem has native conversation support through ConversationId, but it behaves differently from Microsoft Graph in several important ways.

Like Exchange Online (Microsoft Graph), on-premises Exchange assigns a ConversationId to each message. Nylas maps this to the thread’s id field. This means Exchange threading is based on the server’s own grouping logic, not heuristic header matching. The grouping is more reliable than IMAP-based providers like Yahoo or iCloud.

Message IDs change when messages move, but thread IDs don’t

Section titled “Message IDs change when messages move, but thread IDs don’t”

This is the most important Exchange-specific behavior. When a message moves from one folder to another, its Nylas message ID changes (this is expected EWS behavior). However, the thread_id remains stable because it’s based on the ConversationId, which doesn’t change when messages move.

If your app stores message IDs from the message_ids array, treat them as folder-specific pointers. The thread ID itself is safe to use as a permanent reference.

Like Microsoft Graph, Exchange threads can include messages across multiple folders (Inbox, Sent Items, Deleted Items). The thread’s folders array reflects all folders containing messages from that conversation. Use the in parameter to filter threads by folder.

Exchange processes received_before and received_after filters at the day level, not second-level. Even though Nylas accepts Unix timestamps, Exchange rounds to the nearest day. Results are inclusive of the specified day.

Exchange relies on a search index for queries. If a message has just arrived but the search index hasn’t refreshed yet, threads containing that message may not appear in filtered results. The refresh interval is controlled by the Exchange administrator. Unfiltered list requests always return the latest threads.

Unlike cloud services, Exchange on-prem rate limits are set by the server administrator. If the Exchange server throttles a request, Nylas returns a Retry-After header. Use webhooks to avoid hitting rate limits.

If EWS isn’t enabled, Nylas can still connect via IMAP for email-only access. When using IMAP fallback, threading uses header-based grouping instead of ConversationId, and the 90-day message cache applies.

The Threads API returns paginated responses. When there are more results, the response includes a next_cursor value. Pass it back as page_token to get the next page:

Keep paginating until the response comes back without a next_cursor.