If you encounter the error message "No route to host" when sending emails, it is likely caused by the wrong mail server option being selected in the control panel. You can choose between "remote" and "local" as the primary options.
This error usually occurs when both the sender and recipient domains exist on the same server, but the recipient server has the wrong mail server selected. You can confirm this by checking that the MX record points to a remote mail server while the domain is listed in the control panel's "local domains" file.
To fix this issue, you need to edit the appropriate files to ensure that the server queries the MX record and uses the results to route the emails externally. The specific steps vary depending on the control panel being used.
For cPanel via CLI, you should remove the domain from the /etc/localdomains file and add it to the /etc/remotedomains file. For DirectAdmin via CLI, remove the domain from the /etc/virtual/domains file.
For cPanel via WHM, go to WHM > Edit DNS Zone File and select the domain from the drop-down list. Scroll to the bottom of the zone file and locate the MailServer Selection section. Select "Remote" and save. Note that you can use the "Automatically Detect" option if the MX points remotely.
For DirectAdmin via the Admin panel, log in as admin, show all users, log in as the user, go to User Panel > domain.com > MX Records, and uncheck the "Local Mail Server" option.
It's important to note that you should not use the mail subdomain as the MX record for remote domains on DirectAdmin servers. The server routes this MX subdomain locally regardless of whether it points to a remote location. You must remove the mail subdomain as the MX record and use a different MX record. That's all there is to it!