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 server that hosts a Java application that is allowed to send out emails. During testing, I want Postfix to send all outgoing email to, however email that sent to needs to be left alone.


  • -->
  • *@* -->
share|improve this question
up vote 4 down vote accepted

I'd like to share some configuration which works in my use case (deliver all mails to my local mailbox regardless of recipent entered).

Running Ubuntu 14.04, postfix version 2.11.0

  • Add the following lines to /etc/postfix/

    sender_canonical_maps = regexp:/etc/postfix/sender_canonical  
    recipient_canonical_maps = regexp:/etc/postfix/recipient_canonical  
    transport_maps = hash:/etc/postfix/transport  
  • Create /etc/postfix/transport with content

    * : yoshi
  • Create /etc/postfix/sender_canonical

  • Create etc/postfix/recipient_canonical/

  • Update configuration:

    sudo postmap /etc/postfix/transport
    sudo postmap /etc/postfix/recipient_canonical
    sudo postmap /etc/postfix/sender_canonical
  • Restart postfix:

    sudo service postfix restart

Now if I run for example the following script:

    mail("", "PseudoFaullt to local Inbox", "This is a manual scam mail, please steal money from yourself.\nThank you for the cooperation");

I receive it with a rewritten recipent in my local inbox. Actually I'm not sure if you need the sender and transport configuration but I had the impression it wasn't working without. So you might want to give it a shot to shorten the process.

Watch out the *_maps* directives in /etc/postfix/ are prefixed with regexp: rather than hash:.

So for your single exception maybe a witty regular expression will do the job.

Very detailed answer about setting up postfix, local inboxes and how to access them with Thunderbird:

Information about sender_canonincal_maps:

share|improve this answer

You can use canonical maps as specified in Postfix documentation here and here.

share|improve this answer
Can you share a simple working config? It could be too many thing to handle on postfix server for a application developer cannot focus on this job. – Dennis Cheung Jul 15 '13 at 3:03

You can use generic maps as described in the Postfix documentation here. If you need other address rewriting rules this document also provides the necessary steps.

share|improve this answer
Can you give an example on what to write in /etc/postfix/generic to acieve my goal? Specificly I would like to know how to handle wildcards. – Nifle Sep 19 '11 at 14:15
I see nothing in the documentation about wildcards, that's why I asked. And if you don't want to help, that's fine but I see NO reason for you to be rude. I hope you had fun on my behalf and I also hope this isn't how people asking questions are generally treated here on serverfault. – Nifle Sep 19 '11 at 15:41
@Nifle What about the third line? @localdomain.local hisaccount+local@hisisp.example – mailq Sep 19 '11 at 16:06
I must be stupid. I can't see how @localdomain.local would match for example and dick.tracy@comicbook.old. – Nifle Sep 19 '11 at 16:10
That's right. It matches *@localdomain.local. If you want to match *@*.* then this is not possible. Postfix is a RFC compliant server. – mailq Sep 19 '11 at 16:15

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.