Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)

like image 209
Ethan Avatar asked May 05 '19 04:05

Ethan


People also ask

Can I schedule an email through Gmail?

On your computer, go to Gmail . At the top left, click Compose. Create your email. Click Schedule send.

How do I automate Gmail API?

Setup the Gmail API The MFA service check will access the Gmail account to get the MFA code requested from the web page. First, we have to enable the API and authenticate to Gmail. This can be done by following their Quickstart guide. Click the “ENABLE THE GMAIL API” form button to generate the credentials.


Video Answer


2 Answers

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.

like image 105
Davis Jones Avatar answered Sep 19 '22 18:09

Davis Jones


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

like image 21
I hope this is helpful to you Avatar answered Sep 19 '22 18:09

I hope this is helpful to you