Weird E-mail Issue where internal mail using domainname will not send mail externally to domain with same domainanme

slimpixel

Registered
Dec 28, 2019
1
0
1
Ohio
cPanel Access Level
Root Administrator
Our hosting server send's all mail using the dns name cpanel.example.com

All e-mails sent to anyone @example.com are handled thru gsuites however all other mail is recieved and sent from the cpanel server itself aka cpanel.example.com

The problem is if anyone sends an email from cpanel.example.com to any address @example.com the server routes it internally thinking that the mailboxes are locally on the server.

For the life of me I cannot figure out what is going on.

Please help.... Thank You
 
Last edited by a moderator:

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
16,617
2,624
363
cPanel Access Level
Root Administrator
Hey there! If your email should all be external for the domain you'll just need to tell cPanel this. You can do that from the cPanel >> Email Routing interface. Just choose the domain from the dropdown list and make sure it is set to the "Remote Mail Exchanger" option. Can you try that and let us know if that improves the behavior?
 

swbrains

Well-Known Member
Sep 13, 2006
306
45
178
Hey there! If your email should all be external for the domain you'll just need to tell cPanel this. You can do that from the cPanel >> Email Routing interface. Just choose the domain from the dropdown list and make sure it is set to the "Remote Mail Exchanger" option. Can you try that and let us know if that improves the behavior?
I have a similar situation where a customer has the hosted domain's nameservers pointing to the registrar (not our server) and they will set up their own MX records there to use external mail servers for their domain. But what should my server's local DNS copy of the MX records look like in this situation? Do they need to point to the external mail server(s) or is cPanel going to figure that out by looking up the nameservers at the registrar and using the MX records there to determine where to send email for this domain?
 

swbrains

Well-Known Member
Sep 13, 2006
306
45
178
Hi,

I want to get some additional clarification on this topic for a couple of different cases where in all cases, mail for the domain should be handled by an external mail server.

When you said earlier, "If the local machine doesn't control the DNS, the local records don't matter at all", does "control the dns" mean "the domain's local NS records point to our own server's nameservers? if so, does that mean that if the local NS records for the domain point externally (not our nameservers) that ALL other local DNS records for the domain (A, MX, TXT, etc.) are ignored by all servers, including our own server, even when sending mail from our own server to an address @ the domain?

I'm trying to clarify how mail sent to a domain parked on our server will react in a couple of different cases:

1) The local copy of the DNS's nameservers point to OUR server (our nameservers) and the local MX records for the domain point to an external mail server.
2) The local copy of the DNS's nameservers point to EXTERNAL nameservers (not ours), the local MX records for the domain point to an external mail server.

In each of these cases, which server will end up processing mail sent to an address @ the domain for messages sent from a server like gmail or yahoo vs. messages sent from our own server.

Finally, what should the "Email Routing" setting for the domain (auto, local, remote) be using in each of these cases?

Sorry for my confusion, and thanks for any clarification you can provide. :)
 

cPanelAnthony

Administrator
Staff member
Oct 18, 2021
1,041
112
118
Houston, TX
cPanel Access Level
Root Administrator
@swbrains Hello! "control the DNS" would refer to your domain using nameservers with IP addresses that resolve to the local cPanel server.

If you have a domain using nameservers that resolve to an external host, none of the DNS records on the cPanel server will be used for this domain. Those DNS records will also be ignored for local mail sending. The server will rely on "local" domains being set to the "local" mail exchanger so it can deliver them properly.

For email routing, there's a good rule of thumb.

  1. If email for a domain is supposed to route through the local cPanel server set it to local.
  2. If email for a domain is supposed to route through an external mail server (Office 365, GSuite, etc) set it to remote.
 

swbrains

Well-Known Member
Sep 13, 2006
306
45
178
Hi,

I had a weird issue that just occurred with one customer we host. Their domain was configured to use external (GoDaddy) nameservers and our server could see that when looking up the DNS from a Perl script. They also had their MX record set to use a ".outlook.com" address to use an external server to receive email for their domain.

However, the DNS on our server (viewed in the WHM Zone Editor) showed an MX record of the local host (their domain) which has an A record pointing to our server. That is, the local MX record on our server for their domain pointed to their domain on our server rather than the external Outlook host.

If I understand correctly, the MX record pointing locally shouldn't matter because the domain's NS records are set at the registrar to point to the registrar's nameservers instead of ours. So all requests for DNS (including MX records) should pull from the registrar's copy of the DNS. In fact, our Perl script which displays the domain's info showed this. It showed the GoDaddy nameservers and the MX record it got from there which was for the Outlook mail server.

In their cPanel account, the Email Routing page was set to "automatic."

However, recent messages sent from our server to @ their domain were going to a :blackhole:, so it appears as though our server was sending mail using the local copy of the MX record in our local DNS which did indeed point to our server as the mail server for the domain. It seems that when sending mail from our server to this domain, the server ignored the fact that the domain's NS records pointed externally, and then failed to get the MX record from the external DNS at the registrar.

Manually changing the Email Routing setting to "remote" seems to have corrected that situation and mail is now delivered externally to that domain.

Email Routing says this about how the "automatic" detects the email routing settings:

Remote Mail Exchanger
No mail exchangers point to an IP address on this server.


But it doesn't really clarify *which* mail exchangers it's looking at. I would have assumed that if the domain's nameservers don't point to my server, then the mail exchangers it looks at are not the ones listed on my server's copy of the DNS. But it seems that's not true. It appears that even if the domain's nameservers point to an external server, the "automatic" setting still looks at the local copy of the DNS to get the MX record for delivery.

Is this the way it's supposed to work? Shouldn't Email Routing of "automatic" follow the path from the nameservers to get the MX record from the server(s) that the nameservers point to, then use that MX record to deliver mail to the domain?

Thanks for any clarification you can provide.
 

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
16,617
2,624
363
cPanel Access Level
Root Administrator
If I understand correctly, the MX record pointing locally shouldn't matter because the domain's NS records are set at the registrar to point to the registrar's nameservers instead of ours. So all requests for DNS (including MX records) should pull from the registrar's copy of the DNS. In fact, our Perl script which displays the domain's info showed this. It showed the GoDaddy nameservers and the MX record it got from there which was for the Outlook mail server.
That sounds right to me.

Is this the way it's supposed to work? Shouldn't Email Routing of "automatic" follow the path from the nameservers to get the MX record from the server(s) that the nameservers point to, then use that MX record to deliver mail to the domain?
This also sounds right to me. I personally get nervous whenever I set something to "automatic" as that just makes me feel like a machine has to think, which makes me nervous.

In our docs at Email Routing | cPanel & WHM Documentation

"Important:
  • This setting only detects the local zone file entries and does not perform an actual DNS lookup. This setting is set upon configuration and does not automatically update. If changes are required, an administrator will need to manually adjust the MX Records in the DNS Zone Manager.
  • If the configured Mail Exchange (MX) records do not resolve, automatic detection will not occur."
So it seems the behavior you're experiencing is expected if I'm reading everything correctly.
 

swbrains

Well-Known Member
Sep 13, 2006
306
45
178
Thanks for the additional information from the docs regarding automatic detection.