超簡単Google Apps Script(GAS)でGmail受信(Google スプレッドシート利用)
超簡単にGoogle Apps ScriptでGmail受信(Google スプレッドシート利用)
1. Google スプレッドシートに受信したい項目を用意
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. 実行
権限を確認して実行
以上、超簡単!
4. 参考
5. 関連記事
この記事が気に入ったらサポートをしてみませんか?