Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am setting up a small email server on a Debian machine, which needs to pick up mail from a variety of POP servers and figure out who to send it to from the address, but I'm not clear what software will do what I need, although it seems like a very simple question!

For example, I have 2 users, Alice and Bob.
Any email to ( etc) should go to Alice, all other mail to should go to Bob. Any email to should go to Bob, and should go to Alice Anything to * should go to Bob And so on...

The idea is to pull together a load of mail addresses that have built up over the years and present them all as a single mailbox for Bob and another one for Alice.

I'm expecting something like Postfix + Dovecot + Amavis + Spamassassin + Squirrelmail to fit the bill, but I'm not sure where the above comes in, can Postfix deal with it as a set of defined regular expressions, or is it a job for Amavis, or something else entirely? Do I need fetchmail in this mix, or is its role now included in one of the other components above.

I think of it as content-filtering, but everything I read about content-filtering is focussed on detecting spam rather than routing email.

share|improve this question

Perdition is excellent for this kind of wizardry.

share|improve this answer

You can feed the mails into Postfix from fetchmail and then configure Postfix with its aliases and virtual maps to drop them into the correct accounts or forward them further.

Dovecot could be used to store and access the mails afterwards via IMAP, but this another problem.

Amavis and Spamassasin are not part of this - Amavis is a virus scanner interface and Spamassasin a spam filter. Both should be part of your installation, but they don't contribute to the problem you outlined.

share|improve this answer
Thanks for that, I'll go and look in the postfix docs. Sorry to see I've been downgraded for the question, I haven't read all the docs on all the components, and didn't expect to, though I have done a lot of hunting through docs and forums before coming here, and it was hard to work out what terms or keywords I was looking for. – rolinger Sep 11 '12 at 8:33
up vote 1 down vote accepted

I have found what seems to be the simplest way to do it, hope this helps someone else...

I've settled on fetchmail+postfix to start with, as once I found out about fetchmail multidrop, I had the right terminology to get started!

In my /etc/fetchmailrc I have multiple sections like this, one for each ISP who I still use for email

poll [one ISP's mailserver] protocol POP3
  aka [domain name this needs to pick up for from this mailserver]
  aka [other domain name this needs to pick up for from this mailserver]
  envelope Envelope-to
  user "[my login name on mailserver]" there with password "[my password on mailserver"]
  is * here
  smtpaddress [ISPOne (this is appended to all emails passed on to postfix)]

This picks up the mail from the ISP and fires it into my local postfix.

The 'smtpaddress' bit was the hardest to find, it looks like not many people write about using it. Without that (eventually found hiding in plain view in the fetchmail docs!), all mails from all ISPs were having domains replaced by localhost so I couldn't do different routing from different ISPs. For example, on one domain I want to catch all mails for spam processing, on another I can ruthlessly discard any unwanted addresses.

Then in my postfix configuration, I create /etc/postfix/virtual-regexp with lines like

# Main users, any mail prefixed by a local user and my choice of separator (- or _)
# is delivered to that local user
/^(alice|bob)(-.+|_.+|)@.*$/ $1@localhost

# Standard addresses routing
/^(postmaster|root|abuse)@ISPTwo$/   bob@localhost
/^(mail|sales)@ISPTwo$/   bob@localhost
# simple routing of local users without suffixes from ISPTwo
/^alice@ISPTwo$/ alice@localhost
/^bob@ISPTwo$/ bob@localhost
# fall through to catch-all while I check it
/^.*@ISPTwo$/ bob@localhost

Then run

 sudo postmap /etc/postfix/virtual-regexp

to create /etc/postfix/virtual-regexp.db and finally add the following line to /etc/postfix/

virtual_maps = regexp:/etc/postfix/virtual-regexp

Finally, restart/reload postfix to use the new configuration.

And when (not if!) your carefully crafted regex all goes wrong, make good use of

sudo postmap -q "bob_and-alice@ISPTwo" regexp:/etc/postfix/virtual-regexp

which replies with the destination routing from your regex file. Actually, the sensible administrator will use that to test the settings before applying them, but I didn't find out about it until I'd had problems!

The above works for me, mail routes where it should, and fires on to dovecot for IMAP delivery, hope it helps someone else too!

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.