Created
October 7, 2023 07:18
-
-
Save chxru/3525322af3f0ff821d6f91fb0c3ce86a to your computer and use it in GitHub Desktop.
Auto delete old IESL emails from gmail
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function auto_trash_old_iesl_emails() { | |
const emails = GmailApp.search('from:ieslweb@iesl.lk') | |
if (emails.length === 0) { | |
// return if no email found | |
console.log("No emails found!") | |
return | |
} | |
for (const email of emails) { | |
const lastUpdateOn = email.getLastMessageDate() | |
const age = ((new Date()) - lastUpdateOn) / (1000 * 60 * 60 * 24) // in days | |
if (age > 7) { | |
console.log('Moving ', email.getFirstMessageSubject(), ' to trash, ', age, ' days old') | |
email.moveToTrash() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment