LoginSignup
5
3

More than 5 years have passed since last update.

Google Apps Script でメールにアクセスする方法メモ

Last updated at Posted at 2016-03-31

ラベル操作

メールのスレッドをラベルで取得する

  var target_label = '取得したいラベル名';
  var mail_by_label = GmailApp.getUserLabelByName(target_label);
  var threads = mail_by_label.getThreads();

各スレッドのメールを取得する

  var messages;
  for (var i = 0, l = threads.length; i < l; i++) {
    messages = threads[i].getMessages();
    // スレッド内のメール一件ごとの処理をここで書く
  }

処理したスレッドからラベルを外す

mail_by_label threads は前述)

  mail_by_label.removeFromThreads(threads);

トリガーを設定して受信メールを操作しているときなどは忘れずに。

5
3
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
5
3