Setting Up Auto Deletion
Set up your inbox to automatically delete marked emails after a time period. If you don’t feel comfortable working with code, then feel free to ignore this feature
Setting Up The Script
Access Google Scripts
Left Click on New Project in the sidebar
Delete the starting code and paste the code below into the file
function auto_delete_mails() { var label = GmailApp.getUserLabelByName("Delete Me"); // A label that signifies emails marked for deletion if(label == null) { GmailApp.createLabel('Delete Me'); } else { var delayDays = 2 // Number of days before messages are moved to trash var maxDate = new Date(); maxDate.setDate(maxDate.getDate()-delayDays); var threads = label.getThreads(); for (var i = 0; i < threads.length; i++) { if (threads[i].getLastMessageDate()<maxDate) { threads[i].moveToTrash(); } } } }
Type in some words between the quotation marks for the label name that marks them for deletion
Type in the number of days before a message with the label will be auto deleted in the red box below the label name
Left Click on “Untitled File” in the top left corner to change the name of the file
Type in the name and Left Click Rename to save changes
Left Click Triggers in the sidebar
Left Click Add Trigger on the bottom right
Set the options to be the same as the picture shown below, or change to your liking if you understand their function. See the Official Google Documentation for more information
Left Click Save at the bottom (If you run into some errors during the process, refer to our troubleshooting links below)
Common Issues
Deleting Scripts
Access Google Scripts
Left Click My Triggers on the left sidebar
Left Click the Three Dots on the right of the trigger and then click Delete Trigger
Left Click Delete Forever when the warning appears
You can now take control of your email with these powerful inbox management tools. Explore some more possibilities by reading through the documentation for Google Scripts!