Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Remove script for Gmail that delets all email threads/messages that match search for when Gmail can't do it itself

Remove script for Gmail

function Intialize() {

function Install() {


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

function purgeGmail() {
  var search = "";
  var threads =, 0, 100);
  for (var i=0; i<threads.length; i++) {
    var thread = threads[i];
  1. Go to and create a new script
  2. Copy the above to the script input
  3. Click the save icon
  4. Click the "Run" menu
  5. Click the "Install" submenu entry
  6. Wait a few days, it will delete 100 messages each 10 minutes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment