首页 > 解决方案 > 提取 gmail 数据(最后一次联系的日期)到谷歌表

问题描述

我试图在谷歌电子表格上收集与一个特定电子邮件地址相关的最新活动的日期。

所以理想情况下,我想输入一个电子邮件地址列表,并在下一列中显示最新交互的日期(传入或传出的电子邮件)

我一直在寻找一个附加组件,但现在没有运气。

任何人都可以帮忙吗?

非常感谢,

杰里米

标签: google-sheetsgmailgmail-addons

解决方案


Solution

This can easily be achieved using Apps Script. In the Spreadsheet with your email addresses go to Tools->Script Editor and use the code below by running the script (Run->Run function -> myFunction).

This is the piece of code that performs what you were trying to achieve with comments explaining how it works:

function myFunction() {
  // Get the value in the cell A1 (which will have the email to check the latest interaction)
  var ss = SpreadsheetApp.getActive().getSheetByName('Sheet1').getRange('A1').getValue();
  
  // Search the date of the last message of the search from the email in cell A1 and log it
  var latestEmail = GmailApp.search('from:"'+ss+'"')[0].getLastMessageDate();
  Logger.log(latestEmail);
  
  // Print the date on the cell to the right
  SpreadsheetApp.getActive().getSheetByName('Sheet1').getRange('B1').setValue(latestEmail);
}

I hope this has helped you. Let me know if you need anything else or if you did not understood something. :)


推荐阅读