¡Estoy buscando hacer un bucle para limpiar ~ 1000000 correos electrónicos, cualquier ayuda apreciada!
function batchDeleteA() { var batchSize = 100 // Process up to 100 threads at once var threads = GmailApp.search('label:inbox older_than:2d'); for (j = 0; j < threads.length; j+=batchSize) { GmailApp.moveThreadsToTrash(threads.slice(j, j+batchSize)); } }Si se trata de un bucle grande, probablemente desee utilizar un sistema de cola en el que utilice tiempos de espera para realizar el bucle. Idea básica a continuación con matriz codificada.
function batchDeleteA() { //var batchSize = 100; var batchSize = 3; // var threads = GmailApp.search('label:inbox older_than:2d'); var threads = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; var removeBatch = function() { var batch = threads.splice(0, Math.min(batchSize, threads.length)); // GmailApp.moveThreadsToTrash(batch); if (threads.length) { console.log("remaining: ", threads.length); window.setTimeout(removeBatch, 1); } else { console.log("complete"); } }; removeBatch(); } batchDeleteA()Si está limitado, puede aumentar el tiempo de espera de 1 a una mayor cantidad de milisegundos.