Schedule email messages to send in the future
The Nylas Email API allows you to schedule email messages to be sent in the future. This means you can draft an email message in advance and schedule it to send when the time is just right — for example, when you want to announce a new version of your product.
This page explains how to schedule email messages with Nylas.
How scheduled send works
When you make a request to the Send Message endpoint, you can define your preferred send time (in Unix epoch format) in the sent_at field.
If the end user’s provider is Google or Microsoft, you can choose to store the scheduled email message in their Drafts folder on the provider. In this case, you can schedule it to send any time in the future.
You can also choose to have Nylas store the email message until its send time, which must be between 2 minutes and 30 days in the future.
Before you begin
Before you start scheduling email messages, you need the following prerequisites:
- A v3 Nylas application.
- A working authentication configuration. Either…
- A Google or Microsoft grant with at least the following scopes:
- Google:
gmail.send - Microsoft:
Mail.ReadWriteandMail.Send
- Google:
Schedule an email message
To schedule an email message to be sent in the future, make a Send Message request that includes the sent_at field, and provide the time (in Unix epoch format) when you want the email message to be sent. Nylas returns a schedule_id that you can use to reference the scheduled message.
curl --request POST \ --url https://api.us.nylas.com/v3/grants/<NYLAS_GRANT_ID>/messages/send \ --header 'Authorization: Bearer <NYLAS_API_KEY>' \ --header 'Content-Type: application/json' \ --data '{ "subject": "Reaching out with Nylas", "body": "Hey! This is testing scheduled emails.", "to": [{ "name": "John Doe", "email": "john.doe@example.com" }], "send_at": 1714478400 }'{ "request_id": "1", "grant_id": "<NYLAS_GRANT_ID>", "data": { "body": "Hey! This is testing scheduled emails.", "from": [{ "email": "nyla@example.com" }], "subject": "Reaching out with Nylas", "to": [{ "name": "John Doe", "email": "john.doe@example.com" }], "reply_to_message_id": "", "send_at": 1714478400, "use_draft": false, "schedule_id": "8cd56334-6d95-432c-86d1-c5dab0ce98be" }}If you’re storing the email message on Nylas, you can schedule it to be sent between 2 minutes and 30 days in the future. If you’re storing it on the provider, you can schedule it to be sent any time in the future.
To store the email message as a draft on the provider, instead of storing it with Nylas, set use_draft to true.
You can also use the Nylas SDKs to schedule an email message, as in the examples below.
!!!include(v3_code_samples/schedules/POST/node.js)!!!!!!include(v3_code_samples/schedules/POST/python.py)!!!!!!include(v3_code_samples/schedules/POST/ruby.rb)!!!!!!include(v3_code_samples/schedules/POST/java.java)!!!!!!include(v3_code_samples/schedules/POST/kotlin.kt)!!!Schedule a draft
If you want to schedule an email message to be sent later, but you’re not quite set on what you want the content to be yet, you can schedule a draft. To do this, make a Send Message request that includes the send_at field, and specify "use_draft": true.
curl --request POST \ --url https://api.us.nylas.com/v3/grants/<NYLAS_GRANT_ID>/messages/send \ --header 'Authorization: Bearer <NYLAS_API_KEY>' \ --header 'Content-Type: application/json' \ --data '{ "subject": "Reaching out with Nylas", "body": "Hey! This is testing scheduled drafts.", "to": [{ "name": "John Doe", "email": "john.doe@example.com" }], "send_at": 1714478400, "use_draft": true }'You can also schedule drafts using the Nylas SDKs.
!!!include(v3_code_samples/schedules/POST/node_draft.js)!!!!!!include(v3_code_samples/schedules/POST/python_draft.py)!!!!!!include(v3_code_samples/schedules/POST/ruby_draft.rb)!!!!!!include(v3_code_samples/schedules/POST/java_draft.java)!!!!!!include(v3_code_samples/schedules/POST/kotlin_draft.kt)!!!TODONylas saves the email message in the end user’s Drafts folder until the defined send_at time.
You can edit a scheduled draft until 10 seconds before the defined send_at time. To do this, make an Update Draft request that includes the draft_id and the fields you want to modify.
If you want to update a draft’s scheduled send time, you must delete the schedule and create a new one.
Read scheduled email messages
You can make a Return Scheduled Messages request or use the Nylas SDKs to get information about all of your scheduled email messages. Nylas returns a list of schedule instructions, including their schedule IDs and information about their status.
!!!include(v3_code_samples/schedules/GET/curl.sh)!!![ { "schedule_id": "8cd56334-6d95-432c-86d1-c5dab0ce98be", "status": { "code": "pending", "description": "schedule send awaiting send at time" } }, { "schedule_id": "rb856334-6d95-432c-86d1-c5dab0ce98be", "status": { "code": "sucess", "description": "schedule send succeeded" }, "close_time": 1690579819 }]!!!include(v3_code_samples/schedules/GET/node.js)!!!!!!include(v3_code_samples/schedules/GET/python.py)!!!!!!include(v3_code_samples/schedules/GET/ruby.rb)!!!!!!include(v3_code_samples/schedules/GET/java.java)!!!!!!include(v3_code_samples/schedules/GET/kotlin.kt)!!!If you see a schedule instruction that you’re interested in, you can pass its schedule_id in a Return Scheduled Message request or using the Nylas SDKs to get information about it.
!!!include(v3_code_samples/schedules-id/GET/curl.sh)!!!{ "schedule_id": "8cd56334-6d95-432c-86d1-c5dab0ce98be", "status": { "code": "pending", "description": "schedule send awaiting send at time" }}!!!include(v3_code_samples/schedules-id/GET/node.js)!!!!!!include(v3_code_samples/schedules-id/GET/python.py)!!!!!!include(v3_code_samples/schedules-id/GET/ruby.rb)!!!!!!include(v3_code_samples/schedules-id/GET/java.java)!!!!!!include(v3_code_samples/schedules-id/GET/kotlin.kt)!!!Stop a scheduled email message
Sometimes, you might decide you don’t want to send a message, and want to stop it from being sent. When this happens, make a Cancel Scheduled Message request with the schedule_id.
!!!include(v3_code_samples/schedules-id/DELETE/curl.sh)!!!{ "Succesfully Request Schedule Deletion": { "value": { "request_id": "8cd56334-6d95-432c-86d1-c5dab0ce98be", "data": { "message": "requested cancelation for workflow" } } }}You can also use the Nylas SDKs to stop a scheduled email message, as in the following code samples.
!!!include(v3_code_samples/schedules-id/DELETE/node.js)!!!!!!include(v3_code_samples/schedules-id/DELETE/python.py)!!!!!!include(v3_code_samples/schedules-id/DELETE/ruby.rb)!!!!!!include(v3_code_samples/schedules-id/DELETE/java.java)!!!!!!include(v3_code_samples/schedules-id/DELETE/kotlin.kt)!!!