Gmail Apps script function to list contents of All draft messages

by Sherif Kamal-ElDin   Last Updated October 17, 2019 23:26 PM - source

I'm looking for a Google Apps script for Gmail that would list the contents of the most recent draft message. So far my code is:

function listDrafts() {
  var drafts = Gmail.Users.Drafts.list('me')
  if (drafts.drafts.length == 0) {
    Logger.log('No draft messages found.');
  } else {
    Logger.log('Drafts:');
    for (var i = 0; i < drafts.drafts.length; i++) {
      var draft = drafts.drafts[i].message.payload.headers[i].value;
      Logger.log('- %s', draft);
    }
  }
}

However, I keep getting an error on run. Appreciate any help.



Related Questions


Permissions error using UrlFetchApp in Gmail Add-on

Updated October 25, 2017 03:26 AM



gmail add-on without mail context

Updated January 16, 2019 21:26 PM