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:
https://pixelbakery.com/recipes/gmail-automatically-delete-or-archive-emails
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:
Capture-d--cran-2023-01-25-085428

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

Capture-d--cran-2023-01-25-085714

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.

Capture-d--cran-2023-01-25-090100

In Google Apps Script

Create the script

In the same Google session, go to https://script.google.com/ and create a new project:
Capture-d--cran-2023-01-25-090653

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:
Capture-d--cran-2023-01-25-091409

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 :
Capture-d--cran-2023-01-25-091807

Now you have to validate the necessary authorizations:
Capture-d--cran-2023-01-25-092110

The script then starts to do its work, in the execution log:
Capture-d--cran-2023-01-25-092300

Schedule the triggering of the script

Now go to the Triggers section of Google Apps Script, and create a new trigger:
Capture-d--cran-2023-01-25-092741

Set the trigger for the autoDelete function to run daily, at night for example:
Capture-d--cran-2023-01-25-092948

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)