How to access date/time of emails using appscript

2020-04-26 02:02发布

问题:

I'm looking at my inbox and I can see the time of the email is being recorded, but I'm having trouble seeing how to grab the date/time of an email, despite looking at the apps script gmail API (https://developers.google.com/apps-script/reference/gmail/gmail-app?hl=ja#detailed-documentation)

Can this be done?

回答1:

How about a following sample? You can retrieve date for each e-mail using getDate(). The sample script is as follows.

Sample script :

var threads = GmailApp.getInboxThreads(0, 50);
threads.forEach(function(messages){
  messages.getMessages().forEach(function(msg){
    var date = msg.getDate(); // date/time
    var body = msg.getBody(); // mail
    Logger.log(date)
    Logger.log(body)
  });
});
  • The information of getDate() is here
  • The information of getInboxThreads() is here

If I misunderstand your question, I'm sorry.