How to solve email problems using exim and cPanel command line
If you’re having a problem with your emails being sent or received on a cPanel or any server with exim installed there is a quick and dirty way to test it using a few commands under SSH.
The first thing to do is to check your DNS and MX records to make sure they are all setup correctly. You can use the website http://www.mxtoolbox.com which I have had good results with.
As you can see in the image to the right, smyl.es is only showing one MX record which is set at 0. If you were using multiple mail servers you would normally have something similar to the first server using 10, second server using 20, and so on. Since I’m only using one mail server there is no need for anything higher than 0. If my mail server was hosted on a server different than the one the website is hosted on the hostname should be the hostname of the mail server.
Check DNS and MX records from WHM
Now that we have verified our MX records are correct from another server we need to check inside WHM for cPanel to make sure everything else is correct. If you found any errors above you can correct them through WHM. If you’re using exim separately from cPanel you will need to manually edit these records via SSH or use something like webmin.
Inside WHM go to DNS Functions >> Edit DNS Zone
(for just MX DNS Functions >> Edit MX Entry)
As you can see from the image on the left we have verified that the MX record is as it showed from MX toolbox, this is where you can change it if you had the wrong details above.
Make sure you put a trailing period after the domain, view the image on the left to see what I’m talking about. You should also verify the A record for whatever hostname your using for your MX record is setup correct as well. You may see a CNAME record for the mail subdomain if you’re using the same server for hosting and email.
Also check to make sure cPanel has "Email Routing for.." set at either Automatically Detect Configuration: Local, or Local Mail Exchanger. If the account is set as Automatically Detect Configuration but does not say Local change it to Local Mail Exchanger.
You can also try running a trace from inside cPanel itself. Login to the cPanel account that is having email problems and click on the "Email Trace" icon. This will bring you to a page similar to the image on the right, as you can see the trace shows a success as "virtual_user to local delivery" … you can use this page as another tool in diagnosing the email problem.
Run Exim test via SSH
After checking to make sure DNS and MX settings are setup correctly lets run a test via SSH using Exim and some debug arguments to see if we can find any errors.
1 |
exim -d -bt im@smyl.es |
As you can see above we’re running exim with the -d and -bt arguments to test email for im@smyl.es
You can see the full linux man page on Exim here: http://linux.die.net/man/8/exim
-bt is for running exim in address testing mode for recipient address deliverability.
-d is for debug information…you can filter this information but I prefer to output everything to track down the problem.
Due to the amount of debug information that is output I wont post the entire debug information from this example but I did run the test and changed the Y to an I in the email to simulate an error and this is what I found in the debug output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
exim -d -bt im@smil.es --------> fail_remote_domains router <-------- local_part=im domain=smyi.es checking domains cached no match for +local_domains cached lookup data = NULL smyi.es in "! +local_domains : ! localhost : ! localhost.localdomain"? yes (end of list) calling fail_remote_domains router rda_interpret (string): :fail: The mail server could not deliver mail to $local_part@$domain. The account or domain may not exist, they may be blacklisted, or missing the proper dns entries. expanded: :fail: The mail server could not deliver mail to im@smyi.es. The account or domain may not exist, they may be blacklisted, or missing the proper dns entries. file is not a filter file parse_forward_list: :fail: The mail server could not deliver mail to im@smyi.es. The account or domain may not exist, they may be blacklisted, or missing the proper dns entries. extract item: :fail: The mail server could not deliver mail to im@smyi.es. The account or domain may not exist fail_remote_domains router forced address failure im@smyi.es is undeliverable: The mail server could not deliver mail to im@smyi.es. The account or domain may not exist, they may be blacklisted, or missing the proper dns entries. search_tidyup called >>>>>>>>>>>>>>>> Exim pid=4754 terminating with rc=2 >>>>>>>>>>>>>>>> |
If you look in the small debug info above we can determine that the problem is in fact a domain problem. Now this will always be different depending on the problem but use this to track it down.
If you’re still having problems you can try some of these commands below:
Add allow_mx_to_ip to Exim configuration
You can add "allow_mx_to_ip = yes" configuration to the /etc/exim.conf file in the off chance that the MX record has an IP set instead of the hostname. This is not recommend by Exim but will allow you to specify an IP in the MX record instead of a hostname. More information: http://www.exim.org/exim-html-3.30/doc/html/spec_11.html#SEC190
1 |
nano /etc/exim.conf |
The following is specific for cPanel scripts:
Update cPanel User Domains
1 |
/scripts/updateuserdomains |
Update cPanel User Mail Permissions
1 |
/scripts/mailperm |
Guided Mail Troubleshooting
1 |
/scripts/mailtroubleshoot |
Fix Common Problems and Quotas
1 |
/scripts/fixeverything |
Force Exim Update and Default Settings
1 |
/scripts/eximup --force |