Skip to content Skip to sidebar Skip to footer

Trying To Understand Getthreads In Gas

I am new to app script and I am trying to read an email from my inbox. I thought that getThreads would do the job but I still don't fully understand how to use it. When I try to ex

Solution 1:

MyLabel is the label of the email. It depends whether you added a label to a specific email or not. You can use the search method instead.

function myFunction(){
   var label = 'yourLabel'; // if no label, remove the label in search// it would be better if you add a label to a specific email for fast and more precise searchingvar searchEmail = GmailApp.search('from:me subject:"' + subject + '" label:' + label + '');
   var threadId = searchEmail[0].getId(); // get the id of the search emailvar thread = GmailApp.getThreadById(threadId); // get email thread using the threadIdvar emailMsg = thread.getMessages()[0]; // get the content of the emailvar emailContent = emailMsg.getPlainBody(); // get the body of the email// check using log
   Logger.log(emailContent);
   // how to open log// Ctrl + Enter// Run this function before checking the log
}

Thanks

Post a Comment for "Trying To Understand Getthreads In Gas"