Postfix forwarding mail with virtual mailboxes present

configurationcyruspostfixredmine

I have mail server setup to use postfix and cyrus imapd + ldap for mail lookups.

Now I would like to specify that for particular address (e.g. someuser@domain.com) instead of delivering mail to mailbox it gets passed to script (ruby script to be more precise). I need this functionality since I would like to have mails passed to particular address to end up on our redmine server. How to do this?

Currently I have in main.cf:

...
mydestination = $mydomain, mail.$mydomain
local_recipient_maps = ldap:/etc/postfix/ldapvirtual.cf
local_transport = lmtp:unix:/var/lib/imap/socket/lmtp
...

/etc/postfix/ldapvirtual.cf is LDAP configuration file to search for mail addresses.

What do I need to configure on postfix?

Best Answer

In master.cf you create a new "ruby" configuration for the ruby script to accept mails. This is done via pipe as described in http://www.postfix.org/pipe.8.html You can probably already see some examples (with pipe in the last column) in your current master.cf. But how to configure it depends on the ruby script and the related system environment.

Then you need a file (for example) /etc/postfix/transport_maps with the content

someuser@example.com    ruby:
other@example.net    ruby:

This will pass mails for these persons to the ruby transport you configured in master.cf as long as you named it "ruby". Then run postmap /etc/postfix/transport_maps.

After that you need a new line in main.cf with

transport_maps = hash:/etc/postfix/transport_maps

Reload the Postfix daemon. From then the configured addresses go through ruby and the others go through the transport configured with local_transport.