Google Apps脚本-GMail到Google表格-在主题的.csv附件中获取最早的未读电子邮件 [英] Google Apps Script - GMail to Google Sheets - Get Oldest Unread Email in Thread's .csv Attachment

查看:72
本文介绍了Google Apps脚本-GMail到Google表格-在主题的.csv附件中获取最早的未读电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,是JavaScript新手.您能提供的任何帮助/指导将不胜感激.

First off: JavaScript novice. Any help/direction you could provide would be greatly appreciated.

我有一个新的业务案例,其中一个GMail框每天要接收4次具有相同主题行的电子邮件,但每次都带有一个新的.csv附件.我已经在GMail中创建了标签,该标签已成功附加到每封电子邮件.我需要能够使用Apps脚本仅处理最旧的未读电子邮件.解析.csv的部分已经测试/成功/完成.但是,每次我运行它时,它都会遍历所有文件,然后再次对其进行处理.

I have a new business case in which a GMail box is going to receive an e-mail 4 times a day with the same subject line, but with a new .csv attachment each time. I've created the label within GMail, and it is attaching successfully to each email. I need to be able to use Apps Script to only process the oldest unread e-mail. The part to parse the .csv is already tested/successful/completed. However, each time I run it, it's looping through all the files, and processing them again.

这是从Gmail邮箱中获取信息的当前代码

Here is the current code for getting information from the GMail Box

// GMail Details
var gmailLabel = ('_Projects/ProjectLabel');
var label = GmailApp.getUserLabelByName(gmailLabel);
var unreadCount = label.getUnreadCount();
var gmailThreads = GmailApp.getUserLabelByName(gmailLabel).getThreads();
Logger.log(label.getUnreadCount());
  for (var i = 0; i < gmailThreads.length; i++) {
   Logger.log(gmailThreads[i].getFirstMessageSubject());
  }
}

该日志确实显示正确存在2个未读线程,并且确实在记录器中显示了主题行.但是,在gmailThreads数组中,我只能看到线程的对象编号.如何获得属于这些线程的每封电子邮件的对象编号?这将是我首先需要解析.csv附件,然后在循环内将其标记为已读(或更改其标签)的电子邮件.

The log does show that there are 2 unread threads correctly, and does display the subject line in the logger. However, within the gmailThreads array, I can only see the object numbers for the threads. How could I get object numbers for each of the e-mails belonging to those threads? This would be the e-mail that I would need to parse the .csv attachment first, then mark as read (or change the label of) within the loop.

再次感谢您的光临!

推荐答案

要获取给定Gmail线程中第一封邮件的ID,您需要致电

To get the IDs of the first messages in a given Gmail Thread, you need to call getMessages() to retrieve all the messages, and then access the first message in the resulting array, with [0]:

var firstMessage = thread.getMessages()[0];

然后,您可以使用 GmailMessage ,例如检索其ID(.getId())或附件(.getAttachments()).

Then you can do a number of things with this GmailMessage, such as retrieve its ID (.getId()) or attachments (.getAttachments()).

这篇关于Google Apps脚本-GMail到Google表格-在主题的.csv附件中获取最早的未读电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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