0
votes

Question about google apps script. I made a script to get some message from my gmail and insert the message into the spreadtheet.

function testFunction() {
  var sheet = SpreadsheetApp.getActiveSheet();
  var row         = sheet.getLastRow() + 1;

  var threadsNew = GmailApp.search('subject: XXXX', 0, 5);

  for(var n in threadsNew){
    var thdNew  = threadsNew[n]; 
    var msgsNew = thdNew.getMessages(); 

    for(m in msgsNew){
      var msgNew  = msgsNew[m];
      var bodyNew = msgNew.getBody();

      sheet.getRange(row, 1 ).setValue(bodyNew);
      row++

      Utilities.sleep(1000);
    }
  }
}

Probrem : I'd like to get a series of email after removing reply-mail from thread, but GmailApp.search method gets all email include reply-mail.

Does Anybody have a good idea to remove reply-mail?

1

1 Answers

1
votes

You could add from:me or to:me to the search string, depending on what you are trying to accomplish. Then you can consider only the first message on each thread. Remove the second loop and set:

var msgNew  = msgsNew[0];
// for each thread found get only the first message