I have a Postfix mail gateway setup and would like to change the recipient address. I want all mail being relayed for ceo@yahoo.com
to instead by relayed to ceo@somewhere.org
I have Postfix configured using smtp_generic_maps
(as below) however this only works for mail being generated on the Postfix server itself. Any mail being relayed through the Postfix server still goes to ceo@yahoo.com
effectively ignoring smtp_generic_maps
. What configuration should I look into to accomplish this?
# grep smtp_generic_maps main.cf
smtp_generic_maps = hash:/etc/postfix/generic
# postmap /etc/postfix/generic
# service postfix reload
# cat /etc/postfix/generic
ceo@yahoo.com ceo@somewhere.org
Best Answer
You shouldn't use
smtp_generic_maps
for thisThe Postfix Address Rewriting Readme describes the correct use for
smtp_generic_maps
:You are trying to use it (instead of replacing local addresses like
ceo@localdomain.local
) for replacing an address with FQDNceo@yahoo.com
. Asyahoo.com
is not configured inmydestination
it is not considered as a local domain, thus not processed by generic(5) mapping.However, you should not configure a domain of someone else as a local domain as it really should be handled by smtp(8) delivery agent instead. Doing so would prevent any user sending mail to any
@yahoo.com
address. That kind of tampering would be technically incorrect and maybe even illegal.Leading users towards company policy by
check_recipient_access
If the problem is that someone is trying to email your CEO to a personal
@yahoo.com
address and you would like to prevent that and force using company emailceo@example.com
instead, you could add acheck_recipient_access
restriction to yourmain.cf
:and then add a reject with a human readable reason into
/etc/postfix/denied_recipients
:(As I used
hash:
in my example, don't forget topostmap /etc/postfix/denied_recipients
.)Using transport(5) table for overriding Postfix built-in defaults
In order to make all
ceo@yahoo.com
be delivered toceo@example.com
you can usetransport_maps
instead ofsmtp_generic_maps
.Add
transport_maps
to your/etc/postfix/main.cf
:And then add to
/etc/postfix/transport
one line forceo@yahoo.com
altering the defaulttransport:nexthop
tovirtual:ceo@example.com
:The other lines just states that no modification is done for
yahoo.com
and the rest, falling back to the defaulttransport:nexthop
behaviour.