The Nylas Email API offers everything you need to manage email messages, threads, and attachments from your project. This guide will walk you through setting up your Nylas application and making your first requests to the Email API.
Before you begin
Section titled “Before you begin”Before you start, you need to have a Nylas account. If you don’t have one already, you can create one here.
Create a Nylas application
Section titled “Create a Nylas application”- Log in to the Nylas Dashboard.
- On the All apps page, click Create new app.
- Select the Data residency.
This determines where Nylas stores your application and user data. Be sure to select the region where your project will be active. You can’t change this setting later.
- Select the Environment.
- Click Create application.
Generate an API key
Section titled “Generate an API key”You’ll need an API key for the last step.
- On your application’s page, click API Keys in the left navigation.
- Click Generate new key.
- Enter an API key name and select the Expiration time.
- Click Generate key.
Create a grant
Section titled “Create a grant”- On your application’s page, click Grants in the left navigation.
- Click Add Account.
You’ll be prompted to enter your email address. If the authentication is successful you’ll see your email address and grant ID with a valid status on the Grants page.
Make your first API call
Section titled “Make your first API call”Now that you’re all set up, it’s time to make your first API call. 🚀 For this example, we’ll be using the Return all Messages endpoint to return the five latest messages from your inbox. Be sure to replace the placeholder fields with your grant ID and API key from the previous step.
curl --request GET \ --url "https://api.us.nylas.com/v3/grants/<NYLAS_GRANT_ID>/messages?limit=5" \ --header 'Accept: application/json, application/gzip' \ --header 'Authorization: Bearer <NYLAS_API_KEY>' \ --header 'Content-Type: application/json'
{ "request_id": "d0c951b9-61db-4daa-ab19-cd44afeeabac", "data": [ { "starred": false, "unread": true, "folders": [ "UNREAD", "CATEGORY_PERSONAL", "INBOX" ], "grant_id": "1", "date": 1706811644, "attachments": [ { "id": "1", "grant_id": "1", "filename": "invite.ics", "size": 2504, "content_type": "text/calendar; charset=\"UTF-8\"; method=REQUEST" }, { "id": "2", "grant_id": "1", "filename": "invite.ics", "size": 2504, "content_type": "application/ics; name=\"invite.ics\"", "is_inline": false, "content_disposition": "attachment; filename=\"invite.ics\"" } ], "from": [ { "name": "Nylas DevRel", } ], "id": "1", "object": "message", "snippet": "Send Email with Nylas APIs", "subject": "Learn how to Send Email with Nylas APIs", "thread_id": "1", "to": [ { "name": "Nyla", } ], "created_at": 1706811644, "body": "Learn how to send emails using the Nylas APIs!" } ], "next_cursor": "123"}
app.get("/nylas/recent-emails", async (req, res) => { try { const identifier = process.env.USER_GRANT_ID; const messages = await nylas.messages.list({ identifier, queryParams: { limit: 5, }, });
res.json(messages); } catch (error) { console.error("Error fetching emails:", error); }});
from dotenv import load_dotenvload_dotenv()
import osimport sysfrom nylas import Client
nylas = Client( os.environ.get('NYLAS_API_KEY'), os.environ.get('NYLAS_API_URI'))
grant_id = os.environ.get("NYLAS_GRANT_ID")
messages = nylas.messages.list( grant_id, query_params={ "limit": 5 })
print(messages)
require 'nylas'
nylas = Nylas::Client.new(api_key: '<NYLAS_API_KEY>')query_params = { limit: 5 }messages, _ = nylas.messages.list(identifier: '<NYLAS_GRANT_ID>', query_params: query_params)
messages.each {|message| puts "[#{Time.at(message[:date]).strftime("%d/%m/%Y at %H:%M:%S")}] \ #{message[:subject]}"}
import com.nylas.NylasClient;import com.nylas.models.*;import java.text.SimpleDateFormat;
public class ReadInbox { public static void main(String[] args) throws NylasSdkTimeoutError, NylasApiError { NylasClient nylas = new NylasClient.Builder("<NYLAS_API_KEY>").build(); ListMessagesQueryParams queryParams = new ListMessagesQueryParams.Builder().limit(5).build(); ListResponse<Message> message = nylas.messages().list("<NYLAS_GRANT_ID>", queryParams);
for(Message email : message.getData()) { String date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"). format(new java.util.Date((email.getDate() * 1000L)));
System.out.println("[" + date + "] | " + email.getSubject()); } }}
import com.nylas.NylasClientimport com.nylas.models.*import java.text.SimpleDateFormatimport java.util.*
fun dateFormatter(milliseconds: String): String { return SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(Date(milliseconds.toLong() * 1000)).toString()}
fun main(args: Array<String>) { val nylas: NylasClient = NylasClient(apiKey = "<NYLAS_API_KEY>") val queryParams = ListMessagesQueryParams(limit = 5, inFolder = listOf("Inbox")) val messages : List<Message> = nylas.messages().list("<NYLAS_GRANT_ID>", queryParams).data
for(message in messages) { println("[" + dateFormatter(message.date.toString()) + "] |" + message.subject + " | " + message.folders) }}