Advanced Gmail Filters That Aren't Available in Gmail

Published in: Gmail

Gmail filters help you automatically sort email messages based on rules. So if your boss has sent an email message, the filter can mark it as important. If the email has the word “Unsubscribe” somewhere in the message body, it can be marked as a promotional message and so on.

How to Create Advanced Gmail Filters

While the built-in Gmail filters are powerful, they do have certain limitations.

For instance, you cannot have a Gmail filter that does case-sensitive search. It will treat WHO and who as same. Gmail filters won’t do pattern matching (regular expressions) so you cannot have a filter for messages that contain phone numbers.

We often get spam messages that have a few dozen addresses in the TO and CC fields but there’s no filter to automatically redirect such messages to the SPAM folder of Gmail. That’s where Google Scripts can help. You can setup advanced filters that aren’t available in the native version of Gmail.

Advanced Gmail Filters

What you see above is a set of 10 Gmail filters that were created with Apps Script. You can have a filter to process messages that contain tons of links. Or messages that have too many attachments. Or messages that have just a word or two in the message body.

The best part is that you don’t have to know scripting to use either of these filters. Just follow these 3 easy steps:

  1. Click here to copy the Gmail Filters sheet into your Google Drive. You can write OFF to deactivate any of the available rules.
  2. Go to the Gmail Filters menu in the sheet, choose Initialize and grant the necessary permissions to the script.
  3. Now choose Turn-on Gmail Filter to activate your filters. You may close the Google sheet now.

Here’s what happens behind the scenes. The script will run in the background every 10 minutes and monitor any new unread messages in your Gmail inbox. It will then run the various rules against these messages. The native filters in Gmail take precedence and then your custom rules specified in the sheet are applied.

You can also look at the source code to understand how the various rules were created.


📮  Subscribe to our Email Newsletter for Google tips and tutorials!
Published in: Gmail

Looking for something? Find here!

Meet the Author

Web Geek, Google Developer Expert
Amit Agarwal

Amit Agarwal is a Google Developer Expert in Google Workspace and Google Apps Script. He holds an engineering degree in Computer Science (I.I.T.) and is the first professional blogger in India. He is the developer of Mail Merge for Gmail and Document Studio. Read more on Lifehacker and YourStory

Get in touch

Google Add-ons

Do more with your Gmail and GSuite account

We build bespoke solutions that use the capabilities and the features of Google Workspace for automating business processes and driving work productivity.

  1. Mail Merge with Attachments
    Send personalized email to your Google Contact with a Google Sheet and Gmail
  2. Save Emails and Attachments
    Download email messages and file attachments from Gmail to your Google Drive
  3. Google Forms Email Notifications
    Send email notifications to multiple people when a new Google Form is submitted
  4. Document Studio
    Create beautiful pixel perfect documents merging data from Google Sheets and Google Forms
  5. Creator Studio for Google Slides
    Turn your Google Slides presentations into animated GIFs and videos for uploading to YouTube