So, I have two servers, I will call then Internal and External.
When I send emails within Internal postfix, it gets relayed by External which does the job of actually sending the email. Normal relay, works great:
sendmail on External -> go to destination
sendmail on Internal -> go to External -> go to destination
I have an aliases file which defines a small list of equivalences on both servers. The main email that I want to alias is 'root'. That works to some extend, that is, I receive all emails sent to the root user from either Internal or External.
The aliases on External is:
root: [email protected], [email protected]
The aliases on Internal is:
root: [email protected]
Yet user2 receives root email from Internal and External.
Is there a way to forward root emails sent by Internal to only [email protected] and not both user1 & [email protected]?
I try the .forward feature instead and that did not help either. [email protected] are still forwarded as such and thus distributed to all the managers of the External server when they should not be.
There is an example of an unwanted email Received, From and To fields:
Received: from halk.m2osw.com (162-226-130-121.lightspeed.frokca.sbcglobal.net [162.226.130.121])
by mail.m2osw.com (Postfix) with ESMTP id 50BD6CE2253
for <[email protected]>; Tue, 1 Oct 2013 08:18:27 -0700 (PDT)
Received: by halk.m2osw.com (Postfix, from userid 0)
id 0443B4C009F; Tue, 1 Oct 2013 08:18:26 -0700 (PDT)
From: Anacron <[email protected]>
To: [email protected]
There are some of the Internal main.cf file (i.e. halk.m2osw.com):
myhostname = halk.m2osw.com
mydestination = halk, halk.m2osw.com, localhost.m2osw.com, localhost
masquerade_domains = m2osw.com
relay_domains = halk.m2osw.com
alias_maps = hash:/etc/postfix/aliases
alias_database = hash:/etc/postfix/aliases
Your aliases are set up correctly, but your hosts are not.
As 84104 hinted, the culprit must be in the way you have set up your postfix/forwarding, either on the Internal or External host, but more - if not highly - likely on Internal. You should start by investigating why the root account (or postmaster) on External receives the Mail you've sent on Internal.
The problem can be as easy as a forgotten
newaliases
run on Internal, or as complicated as a completely wrong setup. It's impossible to solve your problem with the current information available, even more so in the form of Q/A. Have a good, thorough look at the Headers of the wrongly received email in order to trace where it went, and why.P.S. I have implemented part of the functionality you desire at one place I worked at, so it is possible.
Try getting rid of masquerade_domains. It is rewriting halk.m2osw.com to m2osw.com, which is not in mydestination, so it relays it on to the external server.
http://www.postfix.org/postconf.5.html#masquerade_domains