Auto Delete Emails in Gmail
Using this script, you can schedule an add-on in Gmail that automatically checks your mailbox at 2 am GMT every day and deletes the emails labeled **Auto Delete**
. You can also set custom retention periods for different types of emails; for instance, you can configure to delete Amazon order updates after 30 days whereas delete Google Security Alerts after just 7 days.
Instructions
-
Go to script.google.com
- Ensure that you are using the Google Account for which you want to configure the auto email deletion
-
Create a New Project and rename it as
Auto Delete Emails
-
In the code editor, copy and paste the script from the below Github page and save the project.
-
Once the project is saved, select the
installAddon
function and clickRun
-
Give the necessary permissions to allow the script to access your mailbox.
- The script runs entirely within the Google ecosystem, so there’s no risk of data leakage.
-
Once the
installAddon
function finishes running, you should haveAuto Delete
label added to your mailbox with three nested labels.- Each nested label defines the retention period of the email. For example, if an email is labeled
Auto Delete/7
, the email will be deleted once it’s 7 days old.- You can create additional nested labels such as 10, 15, etc. if you need more custom retention periods.
- Each nested label defines the retention period of the email. For example, if an email is labeled
-
Assign the labels to the emails. You can also use the Filters functionality to ease the process. Yay, you are all set. The emails assigned with
Auto Delete
-based labels will be deleted the next time the add-on runs based on their retention periods.- For example:
- If the email is labeled as
Auto Delete
without any nested label, it will be deleted when the add-on runs at 2 am GMT. - If the email is labeled with a nested label as
Auto Delete/7
, it will be deleted if it is 7 days old.
- If the email is labeled as
- Check out this short video on using labels and filters in Gmail:
- For example:
-
You can remove the add-on by going to your project in script.google.com and running the
deleteAddon
function.
Does this add-on developer have access to your emails?
No, all the processes happen within your Google ecosystem. The developer doesn’t have access to any kind of data.
Disclaimer
The script deletes only emails labeled as Auto Delete
. The developer is not responsible for any emails deleted by mistake.