1

I want to delete the following emails:

from:(reply@abc.com) subject:(for sale) older_than:1d

It seems in the old Gmail interface it was possible to create filters to delete these messages. I am not sure in the current Gmail interface (2019) how we can do this. I can search these emails but once I click create filter, the older_than part disappears.

For the old interface there are guidelines like this.

1

Using Google Script:
1. Go to: https://script.google.com
2. Click "New Script"
3. Type this code

// reference: https://medium.com/@fw3d/a-cleaning-robot-for-your-gmail-inbox-f44c01306ea2
// Modify by: Dicky Ibrohim for delete (move to trash) specific subject, sender, and time

function removetotrash() {

  var delayDays = 1; // Impact form email more than 1day
  var maxDate = new Date();
  maxDate.setDate(maxDate.getDate()-delayDays); 

  // What will be executed, adjust the string here
  var searches = [
    '"for sale" from:reply@abc.com'
    ];

  // Looping for 100 last email
  var threads = [];
  for (var i = 0; i < searches.length; i++) {
    var tmp_threads = GmailApp.search(searches[i], 0, 100); // search until 100 mail
    var threads = threads.concat(tmp_threads);
  }

  // Then remove all
  for (var i = 0; i < threads.length; i++) {
    if (threads[i].getLastMessageDate()<maxDate)
    {
      threads[i].moveToTrash();
    }
  }
}
  1. click File --> Save
  2. Make it automation, click on menu "Current project’s triggers",
  3. Click "Create New triger"
  4. Setup hour time, example, script will executed every 3 hours
  5. Save.

I tried it and it went well


Manual Work from Gmail
enter image description here

Then
enter image description here


Then
enter image description here
Do this carefully. when you press the blue button, there is a loading process to complete (Don't do anything until there is a marker successfully).
Then enter image description here Then check result
enter image description here

  • It worked for the first time I created it, but not afterward. So on the next days, I can see emails older than 1d. – apadana Apr 10 at 18:13
  • You can use Google Apps Script with exact above filter. – DavChana Apr 16 at 4:13
  • I have added Google Script in the answer. I tried it and it worked, please try and have a good luck @apadana – user214312 Apr 18 at 12:28
  • @DICKYIBROHIM Thanks! – apadana Apr 18 at 15:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.