使用应用脚本将符合标准的电子邮件导入Google Spreadsheet [英] Import emails that fit criteria to Google Spreadsheet using apps script

查看:90
本文介绍了使用应用脚本将符合标准的电子邮件导入Google Spreadsheet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以创建一个应用程序脚本来监控我的收件箱或Gmail中的某个标签,以及收到电子邮件时,将它导入到Google电子表格中。

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 spreadsheet

这两者中较简单的就是导入所有被某个标签捕获的电子邮件,这很容易通过gmail本身的过滤器完成,所以我认为这将是更简单的选择。

The simpler of the two would be to import all emails that are caught in a certain label, which is easily done using filters in gmail itself, so I'd assume this would be the easier option

如果可能的话,是否有人可以将我链接到一个应用程序脚本,该脚本已经做到了这一点,或者指引我开始正确的方向?我已经有了一些,尽管对应用程序脚本的经验很少,所以对我来说很简单:)

If it's possible, could someone link me to an apps script that already does this or point me in the right direction to get started? I've got some, albeit minimal experience with apps script so go easy on me :)

推荐答案

这是一个小代码首先,我确实将请求限制在前10个线程中,以使其缩短并使用我所拥有的标签......不要忘记在测试之前更改它的名称; - )

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)
    }

这篇关于使用应用脚本将符合标准的电子邮件导入Google Spreadsheet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆