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

How can I forward (or proxy) mail to different smtp servers depending on the To address?

I've got one machine with an SMTP (postfix) server listening on port 25. I want to use Lamson (http://lamsonproject.org/) to handle some incoming mail and some mail I want to have postfix to handle.

My idea is to setup Lamson to listen on a different port, let's say localhost:10025. I then setup postfix to catch all mail by listening on port 25.

How do I configure Postfix to proxy certain mail to Lamson on 10025 and handle all other mail itself?

share|improve this question

1 Answer 1

up vote 12 down vote accepted

Postfix is extremely flexible (and therefore, complex) in its configuration, so there are various ways to achieve this. The simplest way would probably be to use a transport(5) table.

First, enable the use of a transport table in postfix:

    transport_maps = hash:/etc/postfix/transport

You'll also have to make sure that Postfix accepts mails for the addresses that will be handled by Lamson. Have a look at permit_auth_destination for the rules Postfix will apply to determine valid recipient addresses. For the following example, assuming "example.com" is a domain not otherwise known to Postfix, it's probably easiest to simply add it as relay domain:

    relay_domains = example.com

Then, create an appropriate table. E.g. to redirect all mail for the domain "example.com" as well as mail for "user@mydomain.org" to your local Lamson listening at port 10025:

    example.com          smtp:
    user@mydomain.org    smtp:

After that (and then once after every update to the transport table file) don't forget to run:

$ postmap /etc/postfix/transport

This should get you going. Be sure to read the transport(5) man page, which will give you more ideas on how to use this powerful facility.

share|improve this answer
Hi, thanks for the tip. I'm still having problems with getting the mail forwarded after following your instructions. I'm getting NOQUEUE: reject: RCPT from {my-mail-relay} Recipient address rejected: User unknown in local recipient table. Any ideas? –  Mattias Sep 20 '09 at 23:08
Ah yes, you'll also have to make sure, that Postfix accepts mail to be relayed towards example.com (as Postfix is now acting as a relay for Lamson). If your Postfix is mainly serving another domain, the easiest way to achieve this is adding the "Lamson domain" to relay_domains. I updated to answer to incorporate this. –  earl Sep 20 '09 at 23:44
Thanks, after following your steps, I was still having some problems getting postfix to recognize localhost as a valid host. I ran the command postconf -e 'smtp_host_lookup = dns, native' and that solved my problem, postfix is now forwarding the mail I want to Lamson. –  Mattias Sep 21 '09 at 10:42
Good to hear that it works. Instead of changing smtp_host_lookup, you could also use instead of localhost. I've updated the answer to accommodate that improvement. –  earl Sep 22 '09 at 0:29

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.