Skip to content

Instantly share code, notes, and snippets.

@jordanlambrecht
jordanlambrecht / autoDeleteGmail.js
Last active August 14, 2024 18:31
Auto Delete / Archive Emails in Gmail
function autoDelete() {
console.log('Started autoDelete run.');
var delayDays = 2;
var maxDate = new Date();
maxDate.setDate(maxDate.getDate()-delayDays);
var label = GmailApp.getUserLabelByName("delete me");
var threads = label.getThreads();
if(threads.length > 0){
console.log('Found ' + threads.length + ' emails marked for deletion.');
@zoidy
zoidy / autoDeleteGmail.js
Last active October 29, 2024 12:55 — forked from jordanlambrecht/autoDeleteGmail.js
Auto Delete / Archive Emails in Gmail
/*
Original Sources:
- https://pixelbakery.com/recipes/gmail-automatically-delete-or-archive-emails
- https://benbjurstrom.com/purge-email
v1.1
https://gist.github.com/zoidy
Auto-archive and delete Gmail messages based on a defined retention period. Functionality:
- Uses Gmail labels to apply retention rules (archive or delete)