3
4

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.

GASでgmail の情報を抜き出す

Last updated at Posted at 2018-11-05
extractGmail.gs
function extractGmail() {
  
  /* Gmailから特定条件のスレッドを検索しメールを取り出す */
  var terms = 'label:all subject:hoge fuga';
  var msgs = [];
  var threads = GmailApp.search(terms); //スレッドを取得
  var mails = GmailApp.getMessagesForThreads(threads); //スレッドからメールを取得する →二次元配列で格納
  
  /* 各メールから日時、送信元、件名を取り出す*/
  for(var j = 0;j < mails.length;j++){
    msgs[j] = [];
    msgs[j][0] = mails[j][0].getFrom();
    msgs[j][1] = mails[j][0].getDate();
    msgs[j][2] = mails[j][0].getSubject(); 
  }
  
  /* スプレッドシートに出力 */
  if(mails.length>0){
    SpreadsheetApp.getActiveSheet().getRange(1, 1, j, 3).setValues(msgs); //シートに貼り付け
  } 

}
3
4
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
3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?