Ethan
Ethan

Reputation: 3808

Scheduling an email with the Gmail API

I found a similar question from 2016, however at that time Gmail itself did not support scheduled sending of emails.

Now that you can schedule messages to send later directly from Gmail, I was wondering if there was a way to do it with their API.

Interestingly, scheduled emails appear as message objects when calling messages.list, but they do not contain any labels.

Any help would be appreciated! And if it's not possible at the moment, it would be awesome to get a reply from someone at Google about when this will become possible (I believe they officially endorse the gmail-api tag to StackOverflow)

Upvotes: 5

Views: 1771

Answers (2)

Rafa Guillermo
Rafa Guillermo

Reputation: 15377

Unfortunately, there is no Gmail API endpoint for scheduling the sending of emails directly.

One workaround would be to write a script in Google Apps Script (https://script.google.com) which handles the composing of the email you wish to send, as well as a function to send the mail via the API. You can then use the built-in 'Apps Script Project Triggers' feature to trigger the function to run on a schedule; for example on action/event or at a specific/repeated time.

Button for adding trigger to Apps Script

Upvotes: 2

Davis Jones
Davis Jones

Reputation: 1882

I don't think a time-based trigger will work--even if you write the code to store email send data and then build something that regularly checks whether it's time for an email to be sent. See Google's documentation on triggers, and you'll notice that time-based triggers aren't available for Gmail scripts.

Upvotes: 3

Related Questions