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

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

问题描述

我想知道是否可以创建一个应用程序脚本来监控我的收件箱或 gmail 中的某个标签,并在收到电子邮件时将其导入谷歌电子表格

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 电子表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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