1

I am trying to retrieve email threads from only a specific folder which I named 'Approval_needed'. I have found a way to get all of my inbox threads like so from the Google Apps Script Reference page:

var threads = GmailApp.getInboxThreads();
 for (var i = 0; i < threads.length; i++) {
   Logger.log(threads[i].getFirstMessageSubject());
 }

Is it possible to do something like getInboxThreads for folder 'Approval_needed'?
I have searched around and have not found an answer for this. I have found other methods such as getPriorityInboxThreads() and getStarredInboxThreads(), but nothing like getInboxThreads(string).

Kurt Leadley
  • 513
  • 3
  • 20

1 Answers1

2

What you are calling "folder" is actually a "label" in gmail, you can use the getThreads() method on the Label class.

Example from the documentation :

// Log the subject lines of the threads labeled with MyLabel
 var label = GmailApp.getUserLabelByName("MyLabel");
 var threads = label.getThreads();
 for (var i = 0; i < threads.length; i++) {
   Logger.log(threads[i].getFirstMessageSubject());
 }
Serge insas
  • 45,904
  • 7
  • 105
  • 131
  • Thank you for the clarification. I actually google'd "What is a label in google apps script?" and the answer I found was "A user-created label in a user's Gmail account." followed by some label methods. So I wasn't exactly sure what that was for. – Kurt Leadley Jul 20 '16 at 19:57