Skip to content

Instantly share code, notes, and snippets.

@jesliwang
Last active October 13, 2018 05:02
Show Gist options
  • Save jesliwang/325cb308b1d5c4884ccca3f47c81a957 to your computer and use it in GitHub Desktop.
Save jesliwang/325cb308b1d5c4884ccca3f47c81a957 to your computer and use it in GitHub Desktop.
自动删除gmail的邮件
function Intialize() {
  return;
}

function Install() {
  ScriptApp.newTrigger("purgeGmail")
           .timeBased().everyMinutes(10).create();

}

function Uninstall() {
  
  var triggers = ScriptApp.getScriptTriggers();
  for (var i=0; i<triggers.length; i++) {
    ScriptApp.deleteTrigger(triggers[i]);
  }
  
}

function purgeGmail() {
  //var search = "before:2018/08/24";
  var search = "is:unread before:2018/10/12";
  var threads = GmailApp.search(search, 0, 100);
  
  for (var i=0; i<threads.length; i++) {
    var thread = threads[i];
    thread.moveToTrash();
  }
}

function test(){
  
  var search = "category:updates";
  var threads = GmailApp.search(search, 0, 100);
  
  for (var i=0; i<threads.length; i++) {
    var thread = threads[i];
    thread.moveToTrash();
  }
}
  1. 运行环境 script.google.com
  2. 注意,时间间隔只能大于10min,否则的话会不执行
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment