検索式を書きますので、それで見つかったファイルを全て選択して、削除などのアクションをしてください。
細かな調整は各自のお好みで変更してください。
◆1年以上前のファイルサイズの大きなメール(300kB以上)を検索(星を付けたメールは除く)。削除しましょう。
older_than:1y larger:300k -is:starred
◆プロモーションやソーシャルに分類された1か月以上前のメールを検索。削除しましょう
(category:promotions OR category:social) older_than:30d
◆受信トレイの180日以上前のメールを検索。アーカイブして、受信トレイのメール数を減らしましょう
label:inbox older_than:180d
◆プロモーションやソーシャルに入ったメールで2日経ったものを検索。既読にしましょう。
label:inbox (category:promotions OR category:social) older_than:2d
Google AppsScript(GAS)を使うとこれを毎日自動で行ってもらえます。
実行の左のアイコンで保存。関数をcleanUpGmailを選んで実行。初回は権限確認のメッセージが出るのでOKを押してください。
無事実行出来たら一番の難関はクリアです。これを毎日自動で実行してもらいましょう。一度に250通が処理されます。
また余裕があれば、左上の無題のプロジェクトになっているところの名前を「gmail自動処理」などに変更しても良いでしょう。
実行する関数:CleanUpGmailデプロイ:Headイベント:時間主導時間べース:時間ベース時間の間隔:6時間おき
これで1日に4回、合計1000通が自動処理されますので、たくさんメールが溜まっている方でも、1か月程度で全て処理されると思います。
function cleanUpGmail() { // メインの関数の開始ログconsole.log("=== cleanUpGmail start ==="); // 1) 2年以上前 & 300KB以上 & from:gmail.comではない &スター付きではない → 削除console.log("古い大きなメールは削除"); processThreads("older_than:2y larger:300k -from:gmail.com -is:starred", "trash"); // 2)プロモーション orソーシャル & 30日以上前 → 削除console.log("プロモーションとソーシャルは1か月で削除"); processThreads("(category:promotions OR category:social) older_than:30d", "trash"); // 3) 受信トレイ & 180日以上前 →アーカイブconsole.log("受信トレイの180日以上前 →アーカイブ"); processThreads("label:inbox older_than:180d", "archive"); // 4) 受信トレイ &プロモーション orソーシャル & 2日以上前 →既読console.log("受信トレイでプロモーション orソーシャル かつ 2日以上前 →既読"); processThreads("label:inbox (category:promotions OR category:social) older_than:2d", "markRead");console.log("=== cleanUpGmail end ===");}function processThreads(query,action) { // 1回あたり250件だけ処理 var batchSize = 250; //最初の 250 件のみ取得 varthreads =GmailApp.search(query, 0, batchSize); var count =threads.length;Logger.log("検索クエリ: [" + query + "] | 取得スレッド数: " + count); //スレッドごとにアクションを実行threads.forEach(function(thread) {switch (action) {case "trash":thread.moveToTrash(); break;case "archive":thread.moveToArchive(); break;case "markRead":thread.markRead(); break; default:Logger.log("不明なアクション: " +action); } });Logger.log("処理したスレッド数: " + count);}