I want to delete the following emails:

from:([email protected]) 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 Answer 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();

  // What will be executed, adjust the string here
  var searches = [
    '"for sale" from:[email protected]'

  // 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)
  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

enter image description here

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
    Commented Apr 10, 2019 at 18:13
  • You can use Google Apps Script with exact above filter.
    – DavChana
    Commented Apr 16, 2019 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
    Commented Apr 18, 2019 at 12:28
    – apadana
    Commented Apr 18, 2019 at 15:14
  • There is an error when I run the script: Exception: Service invoked too many times for one day: gmail. removetotrash Commented May 14, 2021 at 7:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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