Import emails that fit criteria to Google Spreadsheet using apps script

后端 未结 2 741
暖寄归人
暖寄归人 2020-12-03 04:06

I\'m wondering if it would be possible to create an apps script that monitors my inbox or a certain label in gmail, and when an email is received, import it to a google spre

相关标签:
2条回答
  • 2020-12-03 04:25

    Yes, it is possible to write a script to do what you've outlined. See the GmailApp documentation of Apps Script for methods that you can use to do so.

    0 讨论(0)
  • 2020-12-03 04:28

    Here is a small code to start with, I did limit the request to the first 10 threads to make it short and used a label that I had ... don't forget to change its name before you test it ;-)

        function getMessagesWithLabel() {
         var destArray = new Array();
          var threads = GmailApp.getUserLabelByName('Facebook').getThreads(1,10);
    
          for(var n in threads){
                var msg = threads[n].getMessages();
                var destArrayRow = new Array();
                destArrayRow.push('thread has '+threads[n].getMessageCount()+' messages');
                  for(var m in msg){
                             destArrayRow.push(msg[m].getSubject());
                   }
          destArray.push(destArrayRow);           
                }
        Logger.log(destArray);
        var ss = SpreadsheetApp.getActiveSpreadsheet();
        var sh = ss.getActiveSheet();
        if(ss.getLastRow()==0){sh.getRange(1,1).setValue('getMessagesWithLabel() RESULTS')};
        sh.getRange(ss.getLastRow()+1,1,destArray.length,destArray[0].length).setValues(destArray)
        }
    
    0 讨论(0)
提交回复
热议问题