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 have a Linux server which uses Postfix for email. Its on a dynamic ip so I use the "relayhost" parameter to send outgoing mail through an ssh tunnel to another server on a static ip and from there it goes out to the real world. That's been working fine since about 1998 or so.

I'm currently developing some software for a client, and it sends email to various people in that client's organization based on information in a database. For my initial testing, I created fake people who all had email addresses like ptomblin+client1@{mydomain}.com, which worked fine and sent all the email to me. But now I'm working with a live database, and all the email addresses are for real people in the client's organization. I don't particularly want to send email to those people telling them that the system access they requested has been provisioned, so I'd like a way to redirect all email to that client's domain to either my email address or to a file.

share|improve this question
up vote 3 down vote accepted

If I understand correctly, you want all the mail destinated to be delivered to your mail address or a file, instead of being forwarded to the server specified in relayhost :

step 1: Add to mydestination in so that mail destinated to is delivered locally .

step 2: Setup a catchall for and send all email to your mail address or a file. You can for example use postfix pcre to achieve this.

Expanded step 2

Using postfix pcre is only one way to achieve this among many others . According to this tutorial by garisson :

  1. Create a local user mylocaluser and it's mailbox or maildir
  2. Create a file named aliases-pcre with content :

    /@example\\.com$/ mylocaluser

    add the following lines to (if is in /etc/postfix):

    alias_database = hash:/etc/postfix/aliases
    alias_maps = hash:/etc/postfix/aliases, pcre:/etc/postfix/aliases-pcre
  3. Restart postfix

Now, all mail destinated to * should go to mylocaluser mailbox/maildir.

Again, this is just an example. You can use any other method that best fits your needs. I tend to use pcre a lot because it allows regexp that are a bit more complex.

However, the above would not work as you need virtual domain.

Here's a minimal sample configuration :

alias_database = hash:/etc/aliases
local_recipient_maps = 
relayhost =
virtual_alias_maps = pcre:/etc/postfix/aliases-pcre
virtual_alias_domains =
mydestination = localhost

File /etc/postfix/aliases-pcre

/@example\.com$/ somelocaluser
share|improve this answer
Can you expand on how to do step 2, or point me to some documentation for it? – Paul Tomblin Jul 31 '12 at 18:53
No, it's still not liking the "localpart" - I send emails to and it bounces them with "unknown user paul.tomblin". Email to "" gets delivered to me, so I know the mydestination part is working. – Paul Tomblin Jul 31 '12 at 22:39
I tested my PCRE file using postmap -qand it does match but not, but I suspect that the domain might be already trimmed off by the time local(8) gets the address. – Paul Tomblin Jul 31 '12 at 22:50
May i ask you he content of the pcre file? – user130370 Jul 31 '12 at 22:52
Also, what happens exactly when email "Email to gets delivered to me" : Can you read the mail in your usual mail client or it get delivred on h postfix srver to user ptomblin? – user130370 Jul 31 '12 at 22:54

Ok, Eric got me close to the right path, but not quite there. This is what I did:

  1. In /etc/postfix/

    virtual_alias_domains =
    virtual_alias_maps = regexp:/etc/postfix/virtual_alias
  2. In /etc/postfix/virtual_alias

    /@example\.com/ ptomblin

One postfix reload later and I was away to the races. (By the way, you don't need to do postmap on regular expression files, only hashs)

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.