Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
GMail Auto Archive script for Google Scripts
function gmailAutoarchive() {
var threads ="in:inbox label:auto-archive older_than:2d");
Logger.log("found " + threads.length + " threads:");
for(var i = 0; i < threads.length; i++) {
var thread = threads[i];
Logger.log((i+1) + ". " + thread.getFirstMessageSubject());
var batch_size = 100;
while (threads.length) {
var this_batch_size = Math.min(threads.length, batch_size);
var this_batch = threads.splice(0, this_batch_size);

This comment has been minimized.

Copy link

@felciano felciano commented Oct 27, 2019

Hi @akamyshanov! Thanks for making this gist available. I'm trying to run it to try it out, but keep getting the "App is unverified" error, even for my own account. How do you run this regularly on your end? Are you simply bypassing the warning by going to "Advanced > Go to {Project Name} (unsafe)", or have you submitted this script for Verification?


This comment has been minimized.

Copy link
Owner Author

@akamyshanov akamyshanov commented Oct 28, 2019

Hi @felciano! I suggest you start with Google Apps Script Quickstart and just replace the sample script with this one. I think the key point here is to Enable the Gmail API advanced service.

Just tried it from another Google account and it prompted for authorization automatically during manual run. Subsequent runs just work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.