I am trying to create a script for an autoreply function. I am currently trying to grab each of the emails assigned to a specific label and grab specific details off of each email, however I am receiving an error stating TypeError: threads.getMessages is not a function, even though I have triple checked that this is, indeed, a function of the GMAIL scripting. Have I done something wrong here in this code that may be causing this error?
var labelName = "auto-reply-incoming";
var receivedCount = 0;
// extract emails from label in Gmail
function extractEmails() {
// get all email threads that match label
var receivedSearchQuery = "label:"+labelName+" -is:sent";
var threads = GmailApp.search(receivedSearchQuery, 0, 500);
for (var i=0; i<threads.length; i++) {
//count received emails in label
receivedCount = receivedCount + threads[i].getMessageCount();
//get body of each email
var message = threads.getMessages()[i].getBody();
//get recipient of each email
var recipient = threads.getMessages()[i].getTo();
}
Logger.log(receivedCount);
Logger.log(recipient);
}