Google Script: how to display GmailApp.search - mail data

I'm trying display starred mails in Logger.

function viewStarred() {
  Logger.log( GmailApp.search('is:starred') );
}

but result in my Logger is this:

[GmailThread, GmailThread, GmailThread, GmailThread, .... GmailThread]

how can I display mail subjects? or content...

Here is my screen: here is my logger screen

Upvotes: 1

Views: 1405

Answers (1)

Srik
Srik

Reputation: 7965

What you are seeing is behaviour as expected. If you see the documentation for GmailApp.search, you'll see that it returns an Array of GmailThread objects. Logger.log cannot print out a GmailThread array object directly

So, you have to a. Single out the GmailThread object you want to print b. Print specific information about a GmailThread (subject, sender etc.)

See example below

var threads = GmailApp.search('is:starred');
for (var i in threads){
  Logger.log(threads[i].getFirstMessageSubject());
}

Upvotes: 1

Related Questions