I don't want to delete my messages right away

I don't want to delete my messages right away
Photo by Kony / Unsplash

I have this problem:

  • some messages fill my box (alert message in alert)
  • I need to see them
  • but I don't want to keep them
  • Google filters classify these messages right away
    • if I applied a filter to delete these messages, I would never see them.

(sorry for the pictures in french but you'll get the idea)

I found my salvation in this great Google Apps script by Jordan Lambrecht:
whose purpose is to delete or archive marked emails that are 2 days old (to summarize).

And it goes through the following steps:

  • In GMail :
    • mark emails with a GMail filter
  • In Google Apps :
    • install the script
    • test the script
    • schedule the script to run every night

Mark emails with a filter

This step is well known : create a filter to apply a label to some emails

For example from an email you want to filter:

Define the criteria you want (for example: From [email protected]), then create the filter. Now you can create the new label.


You need to create two new labels with the following precise names:

  • archive me
  • delete me

You can also apply this filter to existing conversations, but to test, just apply it to the selected message. This single message will then be marked delete me or archive me.


In Google Apps Script

Create the script

In the same Google session, go to https://script.google.com/ and create a new project:

In the newly created project, delete the existing code:

function myFunction() {

Instead, paste the code provided on the Git provided by author as is, taking care to give this project a friendly name:

Test the script

After clicking on the Save icon in the project, the Run button appears: select the function you want and click on the button :

Now you have to validate the necessary authorizations:

The script then starts to do its work, in the execution log:

Schedule the triggering of the script

Now go to the Triggers section of Google Apps Script, and create a new trigger:

Set the trigger for the autoDelete function to run daily, at night for example:

Add another trigger for the autoArchive function.

From now on, any new email matching your criteria will be marked. In two days it will be deleted or flagged.

Translated with www.DeepL.com/Translator (free version)