Search code examples
javascriptgoogle-apps-scriptgmail

Google Scripts - getFrom() is not a function error


I had this working before, without an issue, however ever since I put a filter in to remove all threads with more than 1 email it is now coming up with the not a function error. I remove the filter and it still comes up with the error, unsure what has caused this to completely break on me

    function extractEmails() {
  var htmlBody = getEmailHtml();
  var labelName = "auto-reply-incoming";
  // get all email threads that match label
  var receivedSearchQuery = "label:"+labelName+" -is:sent";
  var threads = GmailApp.search(receivedSearchQuery, 0, 500);
    threads.forEach ((t, i) => {
      let messages = t.getMessages();
      let name = messages.getFrom();
      let messageCount = t.getMessageCount();
      if (messageCount > 1) {
        label.removeFromThread(t);
      }
      if (messageCount <= 1) {
        message.reply("Hi " +name+" \n" + "insert text here");
      }
    });
};

Solution

  • accidentally removed part of the script, fixed with the following code:

    messages.forEach ((m, j) => {
          let name = m.getFrom();
          m.reply("Hi " +name+" \n" + "insert text here");
    });