1

I tend to create many filters in Gmail so that lots of types of email I receive daily doesn't interrupt me with new mail notifications, but instead gets assigned a certain label (kind of like how Gmail tried to do automatically, but I would like to have explicit control).

My typical workflow is that I open the email, select the option "Filter message like this one" and leave the auto populated items here (typically sender address or a mailing list name). Then on the next screen, I always select the same options (skip the inbox, apply label [label name is typically one of 2 I mostly use], and also apply to selected messages).

Is there a way to either batch create filter like these (i. e. select a bunch of email by some means, and apply this filter to any that match these senders), or to have some sort of filter template instead of having to check all those boxes each time?

First filter screen

Second filter screen

2
+50

Actually there is a way (I use it myself).

Please follow these steps once:

  1. Go to your Gmail account --> Settings --> Filters and blocked addresses.

  2. Find your "typical" filter from your existing list of filters and check it's box you find on the left side. (make sure you choose just one filter -at least till you get the hang of the process).

  3. Now go to the bottom of the page and on the left hand side click the Export button. Download and save the created mailFilters.xml file.

  4. Make a copy of it (just to be on the safe side), rename it to whatever you want (eg: mailFilters-XYZ.xml). This file will be your template. Open your new template with a basic text editor.

It will look something like this:

<?xml version='1.0' encoding='UTF-8'?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:apps='http://schemas.google.com/apps/2006'>
    <title>Mail Filters</title>
    <id>tag:mail.google.com,2008:filters:1522584886685</id>
    <updated>2019-04-23T01:21:19Z</updated>
    <author>
        <name>your name</name>
        <email>yourname@gmail.com</email>
    </author>
    <entry>
        <category term='filter'></category>
        <title>Mail Filter</title>
        <id>tag:mail.google.com,2008:filter:1522584886685</id>
        <updated>2019-04-23T01:21:19Z</updated>
        <content></content>
        <apps:property name='hasTheWord' value='Company XYZ'/>
        <apps:property name='label' value='Clients/XYZ'/>
        <apps:property name='shouldNeverSpam' value='true'/>
        <apps:property name='smartLabelToApply' value='^smartlabel_personal'/>
        <apps:property name='sizeOperator' value='s_sl'/>
        <apps:property name='sizeUnit' value='s_smb'/>
    </entry>
</feed>

This particular file reads that: when new mail arrives and

Includes the words: Company XYZ   
Do this: Apply label "Clients/XYZ", Never send it to Spam, Categorize as Primary.

As mentioned, you execute the previous steps only one time.

You follow the next steps when you want to create a new filter.

  1. Open your template, change Company XYZ and Clients/XYZ to whatever you like and save the file.

  2. Go back to the bottom of your Gmail account --> Settings --> Filters and blocked addresses and click on the Import filters link.

  3. Choose file and Open file

  4. Create filters. If you want check the Apply new filters to existing email box as well.

  5. Enjoy your new filters.

The beauty of this process is that once you understand it, you can download several -even different- filters in just one mailFilters.xml file, create a "multi-filter" template and change/import them all together or a choice of them.

EDIT following your comment:

"Is there any documentation on the format used in the XML file?"

You can use one of the online .xml viewers (Free Online XML Viewer & Formatter) to help you further analyze the file.

"I would like to use multiple words with AND or OR in the query"

What you need to look into is the Gmail Operators.
As an example, you could apply one filter to all emails from John or Bob or Jane by using

From: client-john@somemail.com OR client-bob@othermail.com OR client-jane@hermail.com
  • Wow, that looks a lot like what I was hoping to find. Is there any documentation on the format used in the XML file? For example, I would like to use multiple words with AND or OR in the query. – PhilippNagel Apr 23 at 3:31
  • Please have a look at my edit. If the answer works accept it so as to help others as well. (Why vote?) – marikamitsos Apr 23 at 13:58

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.