Mail Filer connects to an IMAP e-mail server and downloads any attachments. Which mailboxes are read and which attachments are downloaded are configurable.

Using mailfiler

To get started with Miln Mail Filer, download and expand the executable file onto your computer.

Mail Filer is a single executable file. It does not need to be installed, can be run from any directory, and can be removed by deleting the file.

Let’s walk through an example use of mailfiler and then consider other options. Consider this command line call:

./mailfiler -server

The flags for this call to mailfiler are:

The IMAP4 server to connect to.

What Happens

So what happens when this command is issued?

mailfiler does the following:

Mail Filer will overwrite any existing file with the same name as the attachment.


Mail Filer uses a netrc file to read credentials. This a text file, with should have limited access rights, stored on your computer. For the example call of mailfiler above, the netrc file should contain an entry for the machine

password thisisthemainpassphrasefortheaccount

The location of the netrc file can be specified with the -netrc flag. The credentials used from the file can be specified using the -netrc-machine flag.


Mail Filer can filter mailboxes (-mailbox) and attachments by their name (-name). Only those that match the filter are read and acted upon.

The matching is implemented with Go’s path.Match function:

    { term }
    '*'         matches any sequence of non-/ characters
    '?'         matches any single non-/ character
    '[' [ '^' ] { character-range } ']'
                character class (must be non-empty)
    c           matches character c (c != '*', '?', '\\', '[')
    '\\' c      matches character c

    c           matches character c (c != '\\', '-', ']')
    '\\' c      matches character c
    lo '-' hi   matches character c for lo <= c <= hi

Using filters, you can control which attachments are downloaded from which mailboxes.

Intended Use

Mail Filer is designed to be simple and robust. I designed the tool to be part of a larger workflow and needed consistency and reliability.

As part of business process, I need a specific file type of attachment to be downloaded. This task was previously performed manually and occasionally e-mails were missed.

To run Mail Filer regularly and automatically, I added an entry to DiskStation Manager’s Task Scheduler:

I could have also used a tool like cron, launchd, or systemd.


Below are examples of common uses of Mail Filer.

Download Attachments from the Inbox

Download attachments from e-mails in the inbox and no other mailboxes.

./mailfiler -server -mailbox INBOX

Download Compressed Archives to a Specific Directory

Save attachments with the file extension .zip to the directory ~/zipped/.

./mailfiler -server -name '*.zip' -destination ~/zipped/

Use Alternative Credentials

Use alternative credentials, rather than the default one associated with the server.

./mailfiler -server -netrc-machine mail-alt

Alternative netrc Example

For this example, the ~/.netrc file must contain an entry for the machine mail-alt:

machine mail-alt
password thisisthealternativepassphrasefortheaccount


mailfiler accepts the following command line flags:

Usage of ./mailfiler:
  -config string
        File path to configuration.
  -destination string
        Path to directory to write attachments.
  -h    Show this help message and exit. (shorthand)
        Show this help message and exit.
  -l string
        Directory path to licence certificate files (PEM encoded) (shorthand) (default "~/.miln/")
        Show legal notices and exit.
  -licence string
        Directory path to licence certificate files (PEM encoded) (default "~/.miln/")
  -name string
        Attachment file name filter. (default "*.storereceipt")
  -netrc string
        Path to netrc file for CalDAV authentication. (default "~/netrc")
  -port int
        TCP/IP port of the IMAP server (default 993)
        Quieten non-critical output.
  -server string
        Host of the IMAP server (default "")
        Show licence details and exit.
  -v    Show version details and exit. (shorthand)
        Show version details and exit.


Latest downloads for Mail Filer.


Legal notices associated with Mail Filer.