見出し画像

超簡単Google Apps Script(GAS)でGmail受信(Google スプレッドシート利用)

超簡単にGoogle Apps ScriptでGmail受信(Google スプレッドシート利用)

1. Google スプレッドシートに受信したい項目を用意

FireShot Capture 077 - 無題のスプレッドシート - Google スプレッドシート - docs.google.com

2. GASファイル作成

メニューの「ツール」から「スクリプトエディタ」

function myFunction() {
 
 GmailApp.search('label:inbox is:unread').forEach(function(thread) {

   thread.getMessages().forEach(function(message) {

     var sheet = SpreadsheetApp.getActiveSheet();      
     var lastRow = sheet.getLastRow() + 1;
     sheet.getRange(lastRow, 1).setValue(message.getFrom());
     sheet.getRange(lastRow, 2).setValue(message.getSubject());
     sheet.getRange(lastRow, 3).setValue(message.getPlainBody());
     message.markRead();
   });
 });
}

3. 実行

権限を確認して実行

FireShot Capture 078 - 無題のプロジェクト - プロジェクト編集者 - Apps Script - script.google.com

FireShot Capture 080 - 無題のプロジェクト - プロジェクト編集者 - Apps Script - script.google.com

FireShot Capture 081 - 無題のスプレッドシート - Google スプレッドシート - docs.google.com

以上、超簡単!

4. 参考

5. 関連記事


この記事が気に入ったらサポートをしてみませんか?