如何将特定的Gmail邮件参数发送到Google表格?

时间:2016-06-03 14:58:28

标签: google-apps-script google-sheets gmail gmail-api

我查看了以下问题,其中有一个与Gmail和Google表格相关的示例:How to use Google App Scripts to retrieve Gmail emails in a customised way?

我想知道如何添加其他参数:邮件日期,发件人电子邮件,邮件主题,完整邮件正文。

上述脚本的问题是它从收件箱中的任何线程检索最后一个电子邮件地址。我关心线程和个人信息。

最后,我希望添加一个条款,指定只抓取我在Gmail中标记的邮件的邮件数据。

以下是Gmail APIGoogle Sheets的一些文档。

2 个答案:

答案 0 :(得分:1)

我认为您需要的是Google Apps脚本。因此,通过选中documentation,您可以找到可以在Gmail邮件中执行的不同方法。

对于你的问题:

  

如何添加其他参数:消息   日期,sender email,   message subject,   full message body

正如您在上面的文档中看到的那样。您将在此处找到方法getDate(),它将获取消息的日期和时间。

var thread = GmailApp.getInboxThreads(0,1)[0]; // get first thread in inbox
var message = thread.getMessages()[0]; // get first message
Logger.log(message.getDate()); // log date and time of the message

检查其他链接以获取每个参数的一些示例代码。

另外,只需检查AppScript的documentation,了解如何将其发送到电子表格。

答案 1 :(得分:0)

有关如何添加其他参数的问题:message datesender emailmessage subjectfull message body。 请参阅此文档。

有关如何将其发送到电子表格的App脚本。 首先在驱动器中创建电子表格,请参考以下代码将其添加到其中。

  var ss = SpreadsheetApp.open(DriveApp.getFilesByName('ADD NAME').next()).getSheets()[0]; ss.appendRow(["RESULT"])