Nesting email rules and actions

Latest builds of v3.2 provides new capabilities such as nesting rules or actions. Make sure you upgrade the build to the latest before you proceed to read through this blog post.

This blog post explores how you can nest rules or nest actions like a PRO.

Nesting rules

Preface – Processing emails with Global filters offers the ability to save emails or attachments into different folders based on some criteria and take actions on them.

You do not need to learn about nesting (described here) for most common cases. Nesting is only useful for advanced cases.

If you are not familiar yet with the Global filters, we have a great blog post here that should help you get started.

Proceed to read on only if you are familiar with how Global filters work.

STOP here and read through this blog post to familiarize yourself with Global filters

This post is about how nesting rules can come in handy when you want to cover some advanced scenarios. Some examples where this can be useful include:

  • When no rules match for a specific email, perform certain actions such as move emails to an error folder that you can take a look at.
  • When you may have multiple attachments in an email each of which have different possible actions.
  • When you want to share a set of actions or email filters amongst many rules so you don’t have to re-type them all over again.

The global filters tab in the PRO versions offer you the ability to define three types of rule filters: an Email Filter, a Global Rule or a Negative Rule, Shared Action. The Rule Type dropdown (shown below) enables you to select the type of the rule.

Read on to explore the different rule types below by using an example.

Tutorial with an Example….

Example: Consider an example where we want to target all emails that have the term “Invoice ID” in the Subject. We also want to move the .pdf’s in such emails to a PDF prefixed folder and .doc’s in such emails to another folder prefixed by doc. Also, if no pdf or doc’s are present, we’ll move the email to an “Issues” folder. And lastly we want to use a Shared Action to save the doc/pdf related email header data (from/to/subject etc.) to a database.

Rule types in an email rule
Different Rule Type’s in a Global filter rule

Let’s start by creating a new Email Filter.

Go to the Global filters tab and Add new, in the popup select the Rule Type as shown above and change it to Email Filter if it’s not already selected.

Email Filter: This enables you to instruct the program to filter processing to either a specific email or to target a group of emails matching the filters you specify here. This rule does not, in and of itself, enable you to save emails or attachments to folders or even define actions that you can take after saving files. Those sections will show up disabled as a result.

Read on to see how Email Filters can have Global Rules as child rules…
An Email Filter that matches emails with the Subject containing “Invoice ID”

You can then save this rule and it’ll show up in the Global filters tab as shown below.

Global filters tab showing one Email Filter

Global Rule: This type of rule enables you to specify which attachments you want to filter down to and where to save them. It also enables you to define actions that you can take after saving the file. You can define a Global Rule as a standalone rule (at the root level) or as a child of an Email Filter.

Read on to see how you can setup multiple Global Rule‘s to save files to different folders

To create a Global Rule as a child of an Email Filter, right click on the email filter and add a new Global rule as shown below.

Add a new Global Rule as a child of the Email Filter defined earlier

Let’s have this rule save the email attachments that are PDFs to a “PDF” folder. This has a filter of Attachment count greater than and a filename option of pdf.

Global Rule that saves PDFs to a prefixed folder pdf\ as highlighted

Since this is a “child rule” of the Email Filter we defined above, the Global Rule will only run for emails with a subject that contains “Invoice ID” that we defined earlier. We have also setup a Mark as read action as shown above. You can add any other action like Move email to folder to move the email to a different folder if you want.

Global filters showing Global Rule that’s a child of the Email Filter

Now, let’s define another Global Rule that saves .doc or .docx’s into a different folder. Right click again on the Email Filter in the Global filters tab and select Add new -> Global Rule. Setup the Global Rule as shown below.

Global Rule: Save docx or doc extension attachments to a doc\ prefixed folder

At this point you should see Global filters tab as shown below (Email Filter being the parent with two child Global Rules).

Negative Rule: This type of rule lets you specify “catch-all” actions when none of the Global Rules match. To do this, we will right click on the Email Filter again and select Add new -> Negative Rule. This type of rule doesn’t offer you the ability to save anything (this will show up disabled).

Read on how to setup a Negative Rule under an Email Filter as a “catch-all” rule
Adding a Negative Rule

Let’s now configure the Negative Rule to copy the email to the “Issues” mailbox folder.

If no Global Rule‘s match for this Email Filter, move email to the ‘Issues’ mailbox folder

Lastly, lets create a Shared Action. Go to the Global filters tab and right click anywhere (not on the Email Filter like we did earlier as Shared Action will show up disabled if you do that). Then select Add new -> Shared Action.

Shared Action: This type of rule has no save options enabled but will have additional filters or actions that you can define. These actions are those that you want to share amongst many Global Rules.

Read on to see how to use a Shared Action to save email data to a DB

We’ll create a new Shared Action as shown below.

A Shared Action to save email data to a database

To configure the program to save to a database, refer to this blog post. We won’t show that here.

Now let’s add this Shared Action to the Global Rules we defined earlier. Multi-select the two rules in the filter tab and then right click and select Add ‘Shared Action’ to selected option as shown below.

Add a Shared Action to selected Global Rule‘s

In the popup that follows, select the shared action we called “Save emails to a database” and click OK.

That’s it.

Summary of the final setup for the example

Now we have setup rules to process the emails with the Invoice ID in the Subject with the Email Filter. Then configured child Global Rules to save PDF and DOC attachments to different folders. We also defined a Negative Rule that moves the email to an ‘Issues’ folder when no attachment arrives. Lastly, we configured a Shared Action for the Global Rules to save the email data to a database.

Nesting rules are a great way to take advanced actions

Nesting actions

Similarly you can nest actions inside a rule as shown below after saving the attachment.

The below shows how you can unzip a file, do a document conversion and then save to a database and run a command line operation.

automate email actions: unzip_files
Nest actions inside a Global Rule or a Shared Action

For more on this, read this blog post here.

PRO features: multiple email accounts and rules

The Mail Attachment Downloader FREE versions offer the ability to download emails from only a single email account at a given time. Furthermore, you are restricted to only a single search or filter criteria.

We will explain how the Mail Attachment Downloader PRO versions differs and overcomes these limitations below with the PRO Features: multiple email accounts and rules.

Multiple email accounts

With the free version, you can run a download session for a single email account at a time. To download from another account you will need to pick another account from the Account dropdown.

With the PRO version, you can select multiple accounts  by selecting <multiple@multiple> option from the Account or email pulldown as shown below.

This will bring up the multiple account chooser after which you can select multiple email accounts that have already been configured.

multiple email accounts

Note that prior to selecting these accounts, you will need to add these accounts to the Account list first as individual accounts and then select the <multiple@multiple> option to choose multiple accounts.

Once selected, when Connect and Download is clicked, the program will download emails from multiple emails automatically.

If you have the PRO Server version and you want to download from multiple email accounts in the background, just select <multiple@multiple> first and then go to the Service tab and then click the Install service button.

Multiple email rules

The FREE version only let you specify a single email rule per email account. For example, you could search for emails starting from a certain date (search tab) and also include a Filter (filter tab)  by Subject. This will download all emails from that date that also match the Subject you provided.

This setting is saved per email account. When you switch accounts, you can specify a different search and filter setting that will be remembered for that account.

But what happens when you want to download this Subject to a folder and maybe a completely different email with a different Subject to a different folder and perhaps also run some actions after downloading the file?

You can do so with the Global Filters tab in the PRO versions as shown in the screenshot below.


The global filters tab lets you add one or more rules (order matters).

Ordering: For every attachment (or .eml if Save as .eml was checked), the program scans rules from topmost down (rule by rule) and checks to see if a rule matches all the criteria. When a match is found and a file is saved, no other rules below it are run for that attachment. Note that other attachments in the same email or body (if body hasn’t been saved already) will scan all the rules again from topmost down to find a match for that attachment/body.  Enable and use rule tracing to find out how or why an attachment or a body did not match a rule.

Applies to all email accounts: These rules apply to all accounts you have defined in the Account dropdown by default.  That is, each rule defined here, by default, will apply and run for every download session regardless of the email account that was selected/used to run the download.

You can, if needed, make the rule run only for a specific email account by adding an Account filter as will be explained below.

When using global filters, certain settings in the Search and Filters tab that were set for individual accounts will no longer be used and the UI for these will be disabled.

This is because the Global filters take precedence over the individual settings specified. You can specify the same exact Search or Filter criteria via a global rule as will be shown below.

To replicate the search and filter settings that you had in your free version in the PRO version, the first step is to click Add new filter and enter a rule name for the new filter. Below we’ve entered then name as ‘Payments FY 2016 Q3’ as an example.

rule filter


Account specific rule: If you want this rule to only apply to a specific email account and not all accounts, you should  specify a filter.

In the filters section of the Rule window, click Add -> Filters -> Account and choose the account from the dropdown (see screenshot below, choose Account instead of Header: SUBJECT).

Not doing so will mean that this rule runs for all accounts.

To add the Subject filter (that was previously in the Filters tab), click the Add button below the filter name in the Rule filters and extractions section and click on the Filters sub-menu followed by the Email Subject sub-menu item.    

This will add a new Subject filter to the Filters list as highlighted below. You can then enter the Subject you want to search much like you could have with the Filters tab in the main program window. Click on the Subject text box or click the … button next to get a help on how to specify this filter.

subject filter added

There are three ways you can specify a “match” in Mail Attachment Downloader PRO in almost any field that does a match (Subject, From, To, etc.).

  1. No quotes: In the field if you just specify Payments without quotes, then it will do a substring match. If the word Payments appears anywhere in the Subject it will be a match.
  2. With quotes: Including quotes like ‘Payments’ will do a regular expression match. If it’s just ‘Payments’ with the quotes it will do a substring match just like in (1) above. You can test out the regular expression by clicking the … button to the right of the text input area as shown above.
  3. With quotes and logical operators: You can also include logical operators such as OR, AND, NOT to combine multiple quoted matches. So an entry like ‘Payments’ OR ‘Invoices’ will match any subject where the words Payments or Invoices appear anywhere in the Subject (i.e. a substring match). You can also use parentheses to group these like: NOT (‘Payments’ OR ‘Invoices’) AND ‘Sales’ will match just Sales and not Payments or Invoices.

Use the button to test out your match criteria for any field to see if that is what you want.

Similarly, you could add other filters like by File type filter. 

Click on the Filter file types list item in the list box below the Add button to reveal the file types you want to select. Example below shows how we can filter by file type of Documents. You can add your own in the Other section (comma separated, like .csv, .jpg etc.).

filter by file type


Similarly, you could also extract data from any email header or body or attachment once the subject and file type matches if you would like as shown below.

Click Add -> Extractions -> (pick the wizard or regular expression option).


For more about extractions, check this in-depth guide on how to extract data from emails and attachments.

Choose save filename or format

Once you have the filters and extractions setup, you can pick the filename format as shown below. Click on the little information button next to the filename format to see a list of templates (enclosed between { and }) to include in the filename.

Save filename and format

CUSTOM FOLDERS: You can also include a \ in the Saved filename format field to indicate that a folder needs to be created. The program would automatically create a folder here whenever needed.

For example, {EMAIL_FROM}\{FILENAME}_{ID}{EXT} would create a folder for every senders emails address. This will be automatically created when a new attachment is downloaded.

Click the [i] information button to the right of the Saved filename format area to bring up a guide of all the fields you can insert in here.

TIP: Just double click the field in that popup window and it will insert the field at the current cursor location into the text area.

A few things to also keep in mind:

  • Always include {ID} in the Saved filename format. Excluding the {ID} will result in inconsistent downloads. This is because the program uses multiple threads to download emails simultaneously. If two filenames happen to clash on the filename, you may notice inconsistent behavior.
  • When you are using a shared folder as the Save folder, it MUST be a UNC path (do not use a mapped network drive as these will not work with the service installation).

READ this blog post on how to set the rules up to save different emails or attachments to different folders.

Downloading entire emails (w/o attachments)

Save filename and format

Also, to download the body or download entire emails (even those without attachments), click the ‘Save as .eml‘ checkbox.

Also make sure the ‘Save inline content’ checkbox in the Global filters tab is checked (or if you are using individual account settings, pick the account in the Account dropdown and check the Save inline content in the Search tab).

This will save the entire email (including attachments) as .eml file. If you want just the .eml file, specific a filter in the rule (like we did for Subject) to include just .eml.

If you want to run actions but not save the .eml, just add a delete file action after saving the file.

Download actions

Next we can add download actions that are run after the attachment is saved.

Lets suppose that the document attached in the email was .docx and we want to covert it to a .pdf. This is possible by choosing Add action in the Actions after save section and then clicking on Document conversion menu item as shown below.

Then we have added the document conversion action and you can add a new conversion by clicking on Add conversion button. Once complete, you will see something like the below indicating that Any doc is now converted to a pdf.

doc conversion action added

Save the rule

Now click on the Save button. That’s it, you have created your first rule.

If you want this rule to only apply to a certain email account and not all accounts, you can specify a filter as we did with the Subject instead choose Account filter as explained below.

In the filters section of the Rule window, click Add -> Filters -> Account and choose the account from the dropdown. Then click Save.

Do this for each rule that applies to that account.

Create unlimited number of rules and actions

Similarly, you can create any number of email rules with different save locations and different actions.

This provides rich automation capabilities with ease and enables you to automate backend email to perform more complex tasks.

Multiple rules: Points to remember

email processing

TIP: Keep these in mind when defining multiple rules…

  • All rules are run for every attachment in the email and/or the .eml (if Save as .eml was checked).
  • All rules are run for any account that is selected in the Account dropdown (in the main program window). You can restrict a rule to a specific account by adding an Account filter and selecting the specific account in the dropdown inside the rule configuration.
  • Ordering: Rules are run from the top to down in ORDER they are defined. Drag and drop rules to move them order to affect the ordering.
  • If a Rule matches a given attachment or .eml, then no other rules below it are run for that attachment or .eml.
  • Emails without attachments can run actions as well, you will need to check the Save inline content checkbox in the Global filters tab AND check the Save as .eml checkbox inside the rule (next to the Save folder).
  • Actions in the rule are only run when there is a rules match and a file is saved. If you don’t want to save the file but want to run actions, just add a delete file action after saving the file in the rule.
  • PRO-Server: When making any config change, always uninstall and then re-install the service from the service tab.


This quick post shows how you can add many email accounts and many filters to handle simple automation tasks.

To see the full list of features or download actions the program supports check our PRO page and browse through features described there.

Further reading

Some interesting how-to links and posts for further exploration:

Contact us

Contact us if you have any questions, suggestions about the functionality described in this article.