Skip to content

Send email messages with Kotlin/Java

This page explains how to use the Nylas Kotlin/Java SDK and Email API to send email messages, reply to an email message, and attach files to a draft. For more information, see the Email documentation.

Before you begin

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

Create and send an email draft

This section walks through how to create and send an email draft with the Nylas Kotlin/Java SDK.

The following example creates a Draft object and assigns it a subject and some body text.

You can also add file attachments, message tracking features, and reply-to values. For more information about the data you can add to a draft, see the Drafts references.

Next, add a recipient to the draft.

You can also set the CC and BCC contacts using a similar construction.

Finally, it’s time to send the draft!

Below are the full examples showing how to draft and send an email message.

Reply to an email message

The first step to reply to an email message is to find the thread you want to reply to. The examples below get the most recent email message in an end user’s inbox by returning only the first thread.

Next, create a draft that has the same thread_id and subject as the thread you’re replying to.

Finally, assign the appropriate recipients and send the email message.

Below are the full examples showing how to reply to an email message.

Attach a file to an email message

The Attachments endpoint allows you to create and modify files that you can attach to email messages. The following examples show how to take a file that’s saved locally and upload it to Nylas for use with the Email API.

Next, create a draft to attach the file to.

Finally, attach the file that you uploaded to the draft, and send the draft as an email message.

Below are the full examples showing how to attach a file to an email message.

Track email messages

The Nylas Email API allows you to track email messages, and Nylas generates webhook notifications when certain conditions are met. For more information, see the message tracking documentation.

The examples below enable message open, link clicked, and thread replied tracking for an email message, then send the message.