Retrieve mails of only one specific account with fetchmail

The situation

I have the following ~/.fetchmailrc

poll       protocol pop3 user ""      password "***"            ssl
mda "/usr/bin/procmail -d default -a foo@example-com"

poll       protocol pop3 user ""      password "***"            ssl
mda "/usr/bin/procmail -d default -a bar@example-com"

So, I retrieve all the mails with fetchmail -v -m '/usr/bin/procmail -d %T'.

The problem

But the problem is all the accounts are retrieved.

The question

Is it possible from fetchmail command to ask for retrieving just one specific addresses’ mails?

Asked By: fauve


You can give each account a different name and use the via option


poll foo via ...

poll bar via ...

Now you can specify each one on the command line; fetchmail foo will only fetch mail for that one account.

I use this type of structure for Outlook:

poll outlook via port 993
  proto IMAP
  user is foo here
  password *****

poll outlook2 via port 993
  proto IMAP
  user is bar here
  password *****

This can be implemented as follows in zsh.

Alias and function to retrieve mail

alias retrieveallmails="fetchmail -v -m '/usr/bin/procmail -d %T'" # For all the accounts

function retrievemail()
    # For a specific account
    fetchmail $1 -v -m '/usr/bin/procmail -d %T'

Related completion

_retrievemail_complete() {
    local accounts
    accounts=($(fetchmail --configdump | sed -n 's/.*"pollname":"(.*)",/1/p'))

        '1: :->account' 
        '*:: :->arguments'

    case $state in
            _describe 'accounts' accounts

compdef _retrievemail_complete retrievemail
Answered By: Stephen Harris
Categories: Answers Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.