Outlook has an interesting Auto-Sweep feature that automatically deletes older email messages from specific senders after a certain period of time. The Trash and the Spam folders in Gmail too have a similar auto-purge property and any mail in these folders that is older than 30 days is automatically deleted.
GMAIL AUTO PURGE – DELETE OLD MAILS AUTOMATICALLY
Auto-purging can help keep your mailbox lean and tidy.
For instance, if you have created a rule in Gmail that archives all your newsletter subscriptions to a particular label, these unwanted messages will live forever until you manually purge them. With auto-purging enabled, the older mails of a label are automatically removed from your mailbox.
HOW TO ENABLE AUTO-PURGING IN GMAIL
You can’t enable auto-purging in Gmail for any particular label but there’s a simple Google Script that will bring this missing functionality to your Gmail. The script will basically monitor messages belonging to a particular folder /label in Gmail and purge those that have exceed the retention time.
Here’s how you can get auto-purge to work inside your Gmail:
1. Copy this Google Auto-Purge Script into your Google Drive.
// The name of the Gmail Label that is to be purged?
var GMAIL_LABEL = "Newsletters";
// Purge messages automatically after how many days?
var PURGE_AFTER = "10";
/*
T U T O R I A L
- - - - - - - -
Step 1. Update the values of fields GMAIL_LABEL and PURGE_AFTER above.
Step 2. Go to Run -> Initialize and authorize the script.
Step 3. Go to Run -> Install to install the script.
You can now exit this window and any email messages in Gmail folder will automatically
get purged after 'n' days. The script will run by itself everyday at 01:00 hours.
Also, you may go to Run -> Uninstall to stop the purging script anytime.
*/
function Intialize() {
return;
}
function Install() {
ScriptApp.newTrigger("purgeGmail")
.timeBased()
.at(new Date((new Date()).getTime() + 1000*60*2))
.create();
ScriptApp.newTrigger("purgeGmail")
.timeBased().everyDays(1).create();
}
function Uninstall() {
var triggers = ScriptApp.getScriptTriggers();
for (var i=0; i<triggers.length; i++) {
ScriptApp.deleteTrigger(triggers[i]);
}
}
function purgeGmail() {
var age = new Date();
age.setDate(age.getDate() - PURGE_AFTER);
var purge = Utilities.formatDate(age, Session.getScriptTimeZone(), "yyyy-MM-dd");
var search = "label:" + GMAIL_LABEL + " before:" + purge;
try {
var threads = GmailApp.search(search, 0, 100);
if (threads.length == 100) {
ScriptApp.newTrigger("purgeGmail")
.timeBased()
.at(new Date((new Date()).getTime() + 1000*60*10))
.create();
}
for (var i=0; i<threads.length; i++) {
var messages = GmailApp.getMessagesForThread(threads[i]);
for (var j=0; j<messages.length; j++) {
var email = messages[j];
if (email.getDate() < age) {
email.moveToTrash();
}
}
}
} catch (e) {}
}
2. Set the value of GMAIL_LABEL to the label that you wish to auto-purge and PURGE_AFTER are the number of days for which you to retain a message in Gmail.
3. Go to Run -> Initialize and grant the necessary permissions. This is your personal script and nobody else will ever have access to your data.
Go to Run -> Install to install the auto-purge script.
That’s it. Exit the Google Script and it will continuously monitor that particular Gmail label in the background. If you need to disable auto-purging later, just open the same script in your Google Drive and choose Run -> Uninstall.
0 comments:
Post a Comment