Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
This looks for all mail labeled "To be archived" that is older than 1 day, archives it and removes the label.
function archiveMail() {
var delayDays = 1 // Enter # of days before messages are archived
var maxDate = new Date();
var label = GmailApp.getUserLabelByName("To be archived");
if (label != null) {
var threads = label.getThreads();
for (var i = 0; i < threads.length; i++) {
if (threads[i].getLastMessageDate()<maxDate) {
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.