12

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?

1 Answer 1

20

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:

/etc/postfix/main.cf:
    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:

/etc/postfix/main.cf:
    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 "[email protected]" to your local Lamson listening at port 10025:

/etc/postfix/transport:
    example.com          smtp:127.0.0.1:10025
    [email protected]    smtp:127.0.0.1:10025

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.

4
  • 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, 2009 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, 2009 at 23:44
  • 1
    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, 2009 at 10:42
  • 1
    Good to hear that it works. Instead of changing smtp_host_lookup, you could also use 127.0.0.1 instead of localhost. I've updated the answer to accommodate that improvement.
    – earl
    Sep 22, 2009 at 0:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .