Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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 test-javaapp@my-company.com, however email that sent to sysadmin@my-company.com needs to be left alone.

Basically:

  • sysadmin@my-company.com --> sysadmin@my-company.com
  • *@* --> test-javaapp@my-company.com
share|improve this question

3 Answers 3

up vote 2 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/main.cf

    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

    /.+/ yoshi@localhost.com
    
  • Create etc/postfix/recipient_canonical/

    /.+/ yoshi@localhost.com
    
  • 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:

<?php
    mail("iamroot@serverfault.com", "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/main.cf 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:
http://askubuntu.com/a/209877

Information about sender_canonincal_maps:
http://binblog.info/2012/09/27/postfix-rewrite-the-sender-address-of-all-outgoing-mail/

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 foo.bar@foobar.com 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

 
discard

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.