Skip to content

Using the Nylas Email API

This page explains how to use the Nylas Email API. You’ll learn how to do the following tasks:

  • Read email messages from an account’s inbox.
  • Search for email messages.
  • Update an email message’s labels, file attachments, unread status, stars, folders, and more.
  • Delete drafts, files, and folders.

How the Email API works

The Nylas Email API interacts with users’ providers using their original SMTP/ActiveSync gateways. This means that when you make a Send Message request, for example, Nylas connects to the provider to send an email message as the user. Because of this, providers see the activity as the user sending a message, rather than an external platform making the request on the user’s behalf.

Email messages sent through Nylas have very high deliverability, but might be subject to rate-limiting and abuse detection from the provider. See Improve email deliverability for more information and a list of best practices.

Provider IDs for messages

Nylas v3 uses an object’s provider ID to refer to the object, and different providers return differently formatted IDs. For IMAP messages, Nylas extracts the ID from the message-id header. For Google and Microsoft, the object ID comes from the provider’s internal ID.

Before you begin

To follow along with the samples on this page, you first need to sign up for a Nylas developer account, which gets you a free Nylas application and API key.

For a guided introduction, you can follow the Getting started guide to set up a Nylas account and Sandbox application. When you have those, you can connect an account from a calendar provider (such as Google, Microsoft, or iCloud) and use your API key with the sample API calls on this page to access that account’s data.

One-click unsubscribe requirements for Google messages

As of February 2024, Google requires that users who send more than 5,000 email messages per day to Gmail email addresses include one-click unsubscribe headers in each of their marketing and subscribed emails (see Google’s official Email sender guidelines). This is along with the visible unsubscribe links that must be in the body content of all marketing and subscribed email messages.

To set up one-click unsubscribe headers using Nylas, include the custom_headers object in your Send Message or Create Draft request. This object accepts a set of key-value pairs, each of which represents the header’s name and its value. You must include the following headers:

  • List-Unsubscribe-Post: List-Unsubscribe=One-Click
  • List-Unsubscribe: The unsubscribe link (for example, a mailto link that uses the end user’s email address, or a link to your list management software).
"custom_headers":[
{
"name": "List-Unsubscribe-Post",
"value": "List-Unsubscribe=One-Click"
},
{
"name": "List-Unsubscribe",
"value": "<mailto: [email protected]?subject=unsubscribe>, <https://mailinglist.example.com/unsubscribe.html>"
}
]

Read email messages from inboxes

Messages are the fundamental object in the Nylas platform, and the core building block for most email applications. They contain several pieces of information, such as the message’s timestamp, the sender’s address, the recipients, and the body of the message. They can also contain file attachments, calendar invites, and more.

By default, the Messages endpoint returns the 50 most recent messages, but the following examples use the limit parameter to reduce the number of results to five.

The following examples show how to return the five most recent email messages from an account’s inbox by making a request to the Nylas Email API.

You can also get email messages from your end users’ inboxes using the Nylas SDKs.

Search an inbox for email messages

In Nylas v3, you add query parameters to a Get all Messages request to search for email messages. For more information, see the Messages references.

The following examples show how to search an end user’s inbox for email messages using the Nylas SDKs.

Modify and delete inbox content

Most Nylas Email API endpoints allow you to modify objects using PUT and POST requests. You can make the following changes:

  • Threads and Messages: Modify labels, unread status, stars, and folders. See the Threads and Messages references for more information.
  • Folders and Labels: Update folder and label names. See the Folders references for more information.
  • Files: Upload files to use as attachments. See the Attachments references for more information.

You can also make DELETE requests to certain endpoints. This allows you to delete existing objects, such as Folders.