Thursday 28 February 2019

Email scheduler for Gmail - get draft messages

Overview blog post.

The following Google Apps Script code is designed to get any current draft messages in Gmail and copy their ID/Subject into the spreadsheet (assuming there is an email address in the To part).

By getting the ID of the message we have a way of referring back to it when we later create the scheduler trigger - so it knows exactly which message to send.

Using 'getDraftMessages' allows us to get various elements such as 'getTo' which we use in an if statement to check it is not blank - as some people do use drafts for just storing information so these messages will not be included.
From here 'getId' will allow us to pass this value through to the checkDuplicateDraft function which accounts for a person importing their draft message more than once - hence we need to prevent repeat entries on the spreadsheet.

Once the relevant duplicateFlag value is returned, if all is fine we can proceed to push the message ID and Subject ('getSubject') into an empty array (example blog post on this) to then 'appendRow' which copies the data into the spreadsheet.

No comments:

Post a Comment