Discussion:
rewrite sender address when recipient is non "local"
(too old to reply)
btb
2013-10-21 20:53:46 UTC
Permalink
i have a scenario in which certain email is sent using envelope senders
that contain host names that are known only on the local lan/network,
and unknown on the internet. most mail expressing that characteristic
stays local, but occasionally, some is legitimately destined for the
public internet. to that end, with such mail, i'd like to change the
sender domain part to @example.com, but only if the recipient domain
part does not end in example.com [both the sender and recipient domain
part may be @example.com, @foo.example.com, @bar.foo.example.com, etc].

what is the right method for doing this? given
ADDRESS_REWRITING_README, it seem to possibly be a fit for either
masquerade_domains or smtp_generic_maps, but i'm not certain, and i'm
not sure how to apply selectively.

-ben
Noel Jones
2013-10-21 21:54:20 UTC
Permalink
Post by btb
i have a scenario in which certain email is sent using envelope
senders that contain host names that are known only on the local
lan/network, and unknown on the internet. most mail expressing that
characteristic stays local, but occasionally, some is legitimately
destined for the public internet. to that end, with such mail, i'd
the recipient domain part does not end in example.com [both the
@foo.example.com, @bar.foo.example.com, etc].
what is the right method for doing this? given
ADDRESS_REWRITING_README, it seem to possibly be a fit for either
masquerade_domains or smtp_generic_maps, but i'm not certain, and
i'm not sure how to apply selectively.
-ben
smtp_generic_maps will do that nicely. Add the rewriting on the
"smtp" outgoing transport in master.cf to limit rewriting to
non-local recipient domains only.

#master.cf
# find the existing "smtp unix ... smtp" transport and add to it:
-o smtp_generic_maps=regexp:/etc/postfix/generic.regexp


# generic.regexp
/^(.*)@some\.fantasy\.invalid$/ $***@example.com




-- Noel Jones
btb
2013-10-22 13:41:27 UTC
Permalink
Post by Noel Jones
Post by btb
i have a scenario in which certain email is sent using envelope
senders that contain host names that are known only on the local
lan/network, and unknown on the internet. most mail expressing that
characteristic stays local, but occasionally, some is legitimately
destined for the public internet. to that end, with such mail, i'd
the recipient domain part does not end in example.com [both the
@foo.example.com, @bar.foo.example.com, etc].
what is the right method for doing this? given
ADDRESS_REWRITING_README, it seem to possibly be a fit for either
masquerade_domains or smtp_generic_maps, but i'm not certain, and
i'm not sure how to apply selectively.
-ben
smtp_generic_maps will do that nicely. Add the rewriting on the
"smtp" outgoing transport in master.cf to limit rewriting to
non-local recipient domains only.
#master.cf
-o smtp_generic_maps=regexp:/etc/postfix/generic.regexp
# generic.regexp
thanks. wrt limit rewriting to non-local recipient domains only, by "stays local", i meant local in terms of the local network, not in terms of postfix. postfix is responsible for only systems.example.com:

virtual_mailbox_domains = ldap:$table_directory/virtual_mailbox_domains.cf
Post by Noel Jones
postmap -q 'systems.example.com' ldap:./tables/virtual_mailbox_domains.cf
systems.example.com

while everything else leaves via smtp and is delivered via mx records - some of which is for other recipients ending in @example.com or .example.com [delivered to other hosts on the local network], and the rest of course out onto the internet. how can i apply smtp_generic_maps selectively, for only certain recipient domains [ones not ending in @example.com or .example.com] leaving via smtp - the goal being to rewrite the sender to @example.com for mail destined for the internet?

-ben
Noel Jones
2013-10-22 13:56:54 UTC
Permalink
Post by btb
Post by Noel Jones
Post by btb
i have a scenario in which certain email is sent using envelope
senders that contain host names that are known only on the local
lan/network, and unknown on the internet. most mail expressing that
characteristic stays local, but occasionally, some is legitimately
destined for the public internet. to that end, with such mail, i'd
the recipient domain part does not end in example.com [both the
@foo.example.com, @bar.foo.example.com, etc].
what is the right method for doing this? given
ADDRESS_REWRITING_README, it seem to possibly be a fit for either
masquerade_domains or smtp_generic_maps, but i'm not certain, and
i'm not sure how to apply selectively.
-ben
smtp_generic_maps will do that nicely. Add the rewriting on the
"smtp" outgoing transport in master.cf to limit rewriting to
non-local recipient domains only.
#master.cf
-o smtp_generic_maps=regexp:/etc/postfix/generic.regexp
# generic.regexp
virtual_mailbox_domains = ldap:$table_directory/virtual_mailbox_domains.cf
Post by Noel Jones
postmap -q 'systems.example.com' ldap:./tables/virtual_mailbox_domains.cf
systems.example.com
-ben
Postfix doesn't have a specific feature to rewrite the sender based
on the recipient.

Arrange for internal network traffic to use a specific transport,
such as the "relay" transport, and let internet traffic use the
default "smtp" transport.

# transport
.example.com relay:


-- Noel Jones
btb
2013-10-24 19:47:01 UTC
Permalink
Post by Noel Jones
Post by btb
Post by Noel Jones
Post by btb
i have a scenario in which certain email is sent using envelope
senders that contain host names that are known only on the local
lan/network, and unknown on the internet. most mail expressing that
characteristic stays local, but occasionally, some is legitimately
destined for the public internet. to that end, with such mail, i'd
the recipient domain part does not end in example.com [both the
@foo.example.com, @bar.foo.example.com, etc].
what is the right method for doing this? given
ADDRESS_REWRITING_README, it seem to possibly be a fit for either
masquerade_domains or smtp_generic_maps, but i'm not certain, and
i'm not sure how to apply selectively.
-ben
smtp_generic_maps will do that nicely. Add the rewriting on the
"smtp" outgoing transport in master.cf to limit rewriting to
non-local recipient domains only.
#master.cf
-o smtp_generic_maps=regexp:/etc/postfix/generic.regexp
# generic.regexp
virtual_mailbox_domains = ldap:$table_directory/virtual_mailbox_domains.cf
Post by Noel Jones
postmap -q 'systems.example.com' ldap:./tables/virtual_mailbox_domains.cf
systems.example.com
-ben
Postfix doesn't have a specific feature to rewrite the sender based
on the recipient.
Arrange for internal network traffic to use a specific transport,
such as the "relay" transport, and let internet traffic use the
default "smtp" transport.
thanks for this guidance. i have what [given my testing so far] appears
to be a setup working as desired, but would appreciate any critiques or
feedback wrt considerations i may have overlooked.

# transport used by mail leaving the local network
smtp unix - - - - - smtp
-o smtp_helo_name=msa.example.com
-o smtp_generic_maps=regexp:$table_directory/generic.regexp

# transport used by mail not leaving the local network
example-internal unix - - - - - smtp
-o syslog_name=postfix/example-internal
Post by Noel Jones
cat transports
# handled by postfix virtual(8)
foo.example.com :
# valid/known on the internet
Post by Noel Jones
cat generic.regexp
# rewrite everything that ends in .example.com, except bar.example.com
if !/^(.*)@bar\.example\.com$/
/^(.*)@.*\.example\.com$/ $***@example.com
endif

-ben
Noel Jones
2013-10-24 21:45:40 UTC
Permalink
Post by btb
Post by Noel Jones
Post by btb
Post by Noel Jones
Post by btb
i have a scenario in which certain email is sent using envelope
senders that contain host names that are known only on the local
lan/network, and unknown on the internet. most mail expressing
that
characteristic stays local, but occasionally, some is legitimately
destined for the public internet. to that end, with such mail,
i'd
the recipient domain part does not end in example.com [both the
@foo.example.com, @bar.foo.example.com, etc].
what is the right method for doing this? given
ADDRESS_REWRITING_README, it seem to possibly be a fit for either
masquerade_domains or smtp_generic_maps, but i'm not certain, and
i'm not sure how to apply selectively.
-ben
smtp_generic_maps will do that nicely. Add the rewriting on the
"smtp" outgoing transport in master.cf to limit rewriting to
non-local recipient domains only.
#master.cf
-o smtp_generic_maps=regexp:/etc/postfix/generic.regexp
# generic.regexp
thanks. wrt limit rewriting to non-local recipient domains only,
by "stays local", i meant local in terms of the local network,
not in terms of postfix. postfix is responsible for only
virtual_mailbox_domains =
ldap:$table_directory/virtual_mailbox_domains.cf
Post by Noel Jones
postmap -q 'systems.example.com'
ldap:./tables/virtual_mailbox_domains.cf
systems.example.com
while everything else leaves via smtp and is delivered via mx
records - some of which is for other recipients ending in
@example.com or .example.com [delivered to other hosts on the
local network], and the rest of course out onto the internet.
how can i apply smtp_generic_maps selectively, for only certain
.example.com] leaving via smtp - the goal being to rewrite the
-ben
Postfix doesn't have a specific feature to rewrite the sender based
on the recipient.
Arrange for internal network traffic to use a specific transport,
such as the "relay" transport, and let internet traffic use the
default "smtp" transport.
thanks for this guidance. i have what [given my testing so far]
appears to be a setup working as desired, but would appreciate any
critiques or feedback wrt considerations i may have overlooked.
# transport used by mail leaving the local network
smtp unix - - - - - smtp
-o smtp_helo_name=msa.example.com
-o smtp_generic_maps=regexp:$table_directory/generic.regexp
# transport used by mail not leaving the local network
example-internal unix - - - - -
smtp
-o syslog_name=postfix/example-internal
Post by Noel Jones
cat transports
# handled by postfix virtual(8)
# valid/known on the internet
Post by Noel Jones
cat generic.regexp
# rewrite everything that ends in .example.com, except bar.example.com
endif
-ben
I don't see any problems.



-- Noel Jones

Continue reading on narkive:
Loading...