Email delivered to external recipient when send to a local one

I have a postfix mail server running on a CentOS distb. The problem is that emails sent to local domains should actually be sent to another server  using the same domain.
Let me explain:

My Local Domain: mydomain.com
My External Domain: mydomain.com

My local sender:  webmaster@mydomain.com (local) -> My recipient: username@mydomain.com (external)

So it means that any email sent to the same domain should be send to an external domain with the same name.
LVL 6
Ludwig DiehlSystems ArchitectAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SandyCommented:
You need to configure DNS accordingly as your postfix is picking the domain name from /etc/hosts or local dns servers and delivering the mail to local domain only.

Configure DNS properly to rid of this issue.

TY/SA
0
serialbandCommented:
Check your nsswitch.conf file for the DNS order and change it so that FILES is set after DNS, or change your resolv.conf and put in external DNS IPs.  Some linux distros have deprecated these files and use another tool to control and populate the entries, so you may have to set it there.
0
Ludwig DiehlSystems ArchitectAuthor Commented:
Sorry for taking so long to reply. Unfortunately I can't still get this working.
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Ludwig DiehlSystems ArchitectAuthor Commented:
Anyone?
0
Ludwig DiehlSystems ArchitectAuthor Commented:
Should I close this post then?
0
serialbandCommented:
You might want to set a mail server in house and relay it to your external server.  Click on the Request Attention link, just under your question to get a Moderator to ask for more help.
0
arnoldCommented:
The issue of using a public domain mydomain.com as internal often leads to these issues.
It sounds as though your postfix server is:
1) not configured as a local server for the domain.
2)  you need to define a transport rule that will direct emails on this server destined to mydomain.com SMTP:internalserverIP.

Without the transport rule, the postfix will perform an nslookup to identify where it should deliver the message.
One option I think you referenced is to point the postfix server using /etc/resolv.conf
To your internal DNS server
nameserver internal_server_IP
So long as you have internally defined an MX record for mydomain.com the postfix server will delivere mydomain.com destined emails to the internal server.

There is no way the postfix server can distinguish between user_local@mydomain.com from user_remote@mydomain.com both will be delivered based on your configuration to the same destination be ipt internal or external.
1
Daniel McAllisterPresident, IT4SOHO, LLCCommented:
There is only 1 way I know of to make this work right -- but first, a little background.

E-Mail service follows a very set path:
 - Client submits message to their own server
 - That server examines the "To", "CC", and "BCC" fields and determines the SERVERS it must connect to to deliver the message.
The server is defined by the MX record of the domain of the recipient -- that is, the part after the @
- It is left to the receiving server to determine how the message is to be delivered into the user's mailbox
for example, large ESPs may have different users on different server farms, but messages can be received into any of their mail servers. Its up to them to configure their local delivery system correctly.

So your problem appears to be that you've inadvertently used a REAL (Internet) domain as your LAN domain. Poor choice, for the now-obvious reason.

One thing you can do is configure your local mail servers to accept (as local) all messages for the domain name in question. Then configure a "catchall" account for that domain, and direct mail for that catchall account to the mail servers for the external domain.

If done properly:
- mail for a@domain.com (local) will be delivered locally
- mail for b@domain.com (remote) will fail locally, then be delivered remotely as a result of the catchall rule
HOWEVER:
- mail for c@domain.com (both local and remote) will ONLY be delivered locally. Try as we might, we don't yet have the technology to read users' minds as they compose messages so they can be delivered as intended... the computer will only follow its delivery rules and deliver the message to the first server that says its OK

You've only begun to feel the pain of your unfortunate domain name choice... but I hope this helps.

Dan
IT4SOHO
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ludwig DiehlSystems ArchitectAuthor Commented:
Thx for answering. The reason why I choose this way is because I cannot send unlimited emails from the external email provider (google) for free. So I want to use my internal server for that and the external for users to check their emails and take advantage of the services provided by google like drive,calendar,etc.
Just to let you know, internal server does send emails to domains different from "mydomain", just need to be able to send emails to "mydomain" too.
0
arnoldCommented:
The transport rule will only handle the mydomain..com in the instructed way all others will be handled as normal.

To achieve what you want should use an internal domain separate from the external domain while configuring masquerading on the postfix to alter the sender email address on outgoing emails to reflect the external domain mydomain.com.

If you already setup your own internal mailserver, why continue to use google's?

I.e. You agreed to rent/lease a vehicle.  Later you decided that the the additional costs are a bit much so you bought another vehicle, but continue to renew the rent/lease agreement.
0
Ludwig DiehlSystems ArchitectAuthor Commented:
Thx for replying. The reason why I continue with google is, as I mention before, because of the services it provides: Google Drive, Calendar, among others and all users are already used to it. I know it is not as cheap as it should be, but unfortunately I cannot do anything about that.
So can you tell me a little bit more about your suggestion?
0
arnoldCommented:
/etc/postfix/main.cf

Look at what you have for mydomain.
Here you would setup the internal domain/email addresses. Does your postfix have a backend where the  user/email addresses are within LDAP or heal, etc?

Then look at postfix masquerade setup.
0
Ludwig DiehlSystems ArchitectAuthor Commented:
Thx for your comment, I will try that and tell you my results.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.