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 Answers 2


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>
        <name>your name</name>
        <email>[email protected]</email>
        <category term='filter'></category>
        <title>Mail Filter</title>
        <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'/>

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: [email protected] OR [email protected] OR [email protected]

Example gmail XML code:

Here is my example of what you can import that is a compilation of what i have exported from my own gmail and examples pulled from @marikamitsos 's example of "Gmail Operators"

Note: I took out the, <id>, <updated>, <author>, <content>, <sizeOperator> and <sizeUnit> sections, as they are auto generated and not needed to upload filters to gmail.

Note: Some settings can conflict, you can see your accepted changes after you import, just re-export and you will see what actually takes effect.

Cleaned Up Result

<?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>
        <category term='filter'></category>
        <title>Mail Filter</title>
        <apps:property name='from' value='[email protected]'/>
        <apps:property name='to' value='[email protected]'/>
        <apps:property name='subject' value='ghi'/>
        <apps:property name='hasTheWord' value='replyto: [email protected]'/>
        <apps:property name='doesNotHaveTheWord' value='abc'/>
        <apps:property name='hasAttachment' value='true'/>
        <apps:property name='excludeChats' value='true'/>
        <apps:property name='label' value='Online Subscriptions'/>
        <apps:property name='shouldMarkAsRead' value='true'/>
        <apps:property name='shouldStar' value='true'/>
        <apps:property name='shouldTrash' value='false'/>
        <apps:property name='shouldNeverSpam' value='true'/>
        <apps:property name='shouldAlwaysMarkAsImportant' value='true'/>
        <apps:property name='size' value='2000'/>

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.