I have a Gmail filter that applies a label ('OTPs') to certain incoming messages. They accumulate and I want to keep most for only a couple of days.

I can eliminate them manually by performing a search (e.g. 'older_than:2d label:OTPs -label:GST') and then deleting the results, but I want to automate this process using a filter.

The example below shows a highlighted message thread 'SMS Forwarder' that totals 21 individual messages of which only 7 would match my criteria for deletion, and the remaining 14 would be kept.

enter image description here

  • So, all the messages get forwarded to mail box including OTPs. Now there are 1000s of OTPs sitting there in my mail, which are basically useless now. So, I want to delete them. Now problem with Gmail is, that the filters would work ONLY for the incoming mails, not the existing ones. I want to clear up my inbox by deleting any mail containing the keyword(s) - "OTP" or "One Time Password", including a single mail in a conversation thread. What is the best way to do it? Dec 6, 2021 at 10:20
  • I noticed that you excluded the label GST in your search example in your original post. Are there other labels that will be excluded? Dec 7, 2021 at 3:52

1 Answer 1


Gmail only applies filters to incoming messages. If you want to automate the process, you can use a Google Apps Script that runs on a time schedule and performs a search and then deletes any messages that meet your criteria.

I am creating a script for you to use. Will post it back shortly (making some updates).


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.