0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Project 25Advent Calendar 2019

Day 17

昨日、Gmailに何通メールが届いたか教えてくれるやつ

Posted at

( ゚д゚)ハッ! Advent Calendarのネタが付きかけている!!

というわけで、クソアプリ系のネタです。
Gmailに何通メールが届いたか知るのにいちいちクエリ書いて... っていうのも面倒なので、集計してメール送ってもらうようにしました。

function sumally() 
{
  var n = new Date();
  var y = (function(){this.setDate(this.getDate()-1); return this}).call(new Date);
  var today = n.getFullYear() + "-" + (n.getMonth() + 1) + "-" + n.getDate()
  var yesterday = y.getFullYear() + "-" + (y.getMonth() + 1) + "-" + y.getDate()
  var sentCount = 0, receivedCount = 0;

  //Received count
  var receivedSearchQuery = "before:"+today+" after:"+yesterday+" -is:sent";
  var threads = GmailApp.search(receivedSearchQuery, 0, 500);


  for(var i=0; i<threads.length; i++)
  {
    receivedCount = receivedCount + threads[i].getMessageCount();
  }
  GmailApp.sendEmail(getEmailAddress(), "summary: " + yesterday, receivedCount+" received");
  Logger.log(yesterday +" : "+receivedCount+" received");
}

function getEmailAddress() {
  return YOUR_EMAIL_ADDRESS;
}
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?