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

  1. Go to script.google.com

    1. Ensure that you are using the Google Account for which you want to configure the auto email deletion
  2. Create a New Project and rename it as Auto Delete Emails

  3. In the code editor, copy and paste the script from the below Github page and save the project.

  4. Once the project is saved, select the installAddon function and click Run

    Untitled

  5. Give the necessary permissions to allow the script to access your mailbox.

    1. The script runs entirely within the Google ecosystem, so there’s no risk of data leakage.
  6. Once the installAddon function finishes running, you should have Auto Delete label added to your mailbox with three nested labels.

    Untitled

    1. 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.
      1. You can create additional nested labels such as 10, 15, etc. if you need more custom retention periods.
  7. 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.

    1. For example:
      1. 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.
      2. If the email is labeled with a nested label as Auto Delete/7, it will be deleted if it is 7 days old.
    2. Check out this short video on using labels and filters in Gmail:

    https://www.youtube.com/watch?v=i6FMSvqgWPM

  8. 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.