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.

I have 2 postfix servers (lets say mail.aaa.tld and mail.bbb.tld) that acts as a relays for several domains (lets say x.com, y.com, z.com) that are composed at ccc.tld.

SMTP server at ccc.tld can relay only to one smarthost.

So I need one of two of my postfix relays (let say mail.aaa.tld) to accept mail from @x.com, @y.com, @z.com; send mail that originates from @x.com, @y.com; and relay mail from @z.com to the other relay (mail.bbb.tld) that will actually send mail for @z.com.

Is it possible to configure Postfix to relay mail that comes from specific domain to other/next hop/relay/smarthost?

  • All servers are Centos 5.5 machines with latest Postfix installed (currently v 2.3.3)
  • I've learned a lot about how to relay for destination domain but failed to google any info on how to relay mail that originates from specific domain with postfix.
share|improve this question

migrated from stackoverflow.com Sep 18 '11 at 22:51

This question came from our site for professional and enthusiast programmers.

2 Answers 2

Postfix 2.3 and later has feature called sender_dependent_relayhost_maps.

sender_dependent_relayhost_maps (default: empty)

A sender-dependent override for the global relayhost parameter setting. The tables are searched by the envelope sender address and @domain. A lookup result of DUNNO terminates the search without overriding the global relayhost parameter setting (Postfix 2.6 and later). This information is overruled with relay_transport, sender_dependent_default_transport_maps, default_transport and with the transport(5) table.

Specify zero or more "type:name" lookup tables, separated by whitespace of comma. Tables will be searched in the specified order until a match is found.

For safety reasons, this feature does not allow $number substitutions in regular expression maps.

This feature is available in Postfix 2.3 and later.

in main.cf, add this line

sender_dependent_relayhost_maps = hash:/etc/postfix/relay_zcom

content of /etc/postfix/relay_zcom

z.com     smtp:[mail.bbb.tld]

Don't forget to run postmap hash:/etc/postfix/relay_zcom and postfix reload.

share|improve this answer

1) You use $myorigin parameter if you want to set a specific domain to relay from:

The domain name that locally-posted mail appears to come from, and that locally posted mail is delivered to. The default, $myhostname, is adequate for small sites. If you run a domain with multiple machines, you should (1) change this to $mydomain and (2) set up a domain-wide alias database that aliases each user to user@that.users.mailhost.

Example:

myorigin = $mydomain

2) A better option is to use the access file. Update the file in /etc/postfix/access with the following:

x.com Ok
y.com Ok
z.com Ok

(you can also limit by IP address as well)

Then run:

postmap access

to update the access.db file. Then reload postfix with:

/etc/init.d/postfix reload

See "man 5 access" for more information on access file.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.