Skip to content

Read email messages and threads with Kotlin/Java

This page explains how to use the Nylas Kotlin/Java SDK and Email API to read and search your end users’ email messages and threads. For more information, see the Email documentation.

Messages versus Threads

Messages are the fundamental object of the Nylas platform and the core building block for most email applications. Messages contain several pieces of information, such as when the message was sent, the sender’s address, to whom it was sent, and the message body. They can also contain files (attachments), calendar event invitations, and more.

Threads are first-class objects that represent collections of messages which are related to each other, and result from people replying to an email conversation. For Gmail and Microsoft Exchange accounts, Nylas threads messages together so that they are as similar as possible to their representation in those environments. For all other providers, including generic IMAP, Nylas threads messages using a custom JWZ-inspired algorithm.

For more information, see the Messages and Threads references.

Before you begin

Before you start, you must have done the following tasks:

Read email messages from an inbox

This section walks through how to read email messages from an end user’s inbox.

First, create a Message object and pass a query to it. This returns a list containing only the most recent email message in the end user’s inbox.

Next, print the message subject, unread status, and ID.

Read threads from an inbox

This section shows how to read threads from an end user’s inbox.

First, create a Threads object and pass a query to it. This returns a list containing only the five most recent unread threads in an end user’s inbox.

Next, print the threads’ subjects and participant email addresses.

Search an end user’s inbox

When Nylas runs a search on an end user’s inbox, that search is proxied to the account’s provider. Nylas matches results with synced objects, and returns them. You can search for both email messages and threads.

The examples below show how to search for and read email messages and threads from an end user’s inbox.