2

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
tivnet
  • 435
  • 4
  • 6
Nifle
  • 374
  • 1
  • 8
  • 22

4 Answers4

4

I'd like to share some configuration which works in my use case (deliver all messages to my local mailbox regardless of recipient 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 recipient 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:
https://askubuntu.com/a/209877

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

user2066657
  • 336
  • 2
  • 13
nuala
  • 168
  • 6
1

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

Vladimir Blaskov
  • 6,183
  • 1
  • 27
  • 22
  • 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 C Jul 15 '13 at 03:03
1

in main.cf

recipient_canonical_maps = regexp:/etc/postfix/canonical_maps_recipient

then create /etc/postfix/canonical_maps_recipient and compile with postmap

/sysadmin@my-company.com/  sysadmin@my-company.com
/.*/ test-javaapp@my-company.com
Pieter
  • 778
  • 7
  • 11
-2

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.

mailq
  • 17,023
  • 2
  • 37
  • 69
  • 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
  • Well `*@*.*` is what I asked for, thanks for trying. – Nifle Sep 19 '11 at 16:19