Is there a way to run a program or script on a linux box to see what MX records are used by default when sending outgoing email from mail
or mailx
? I'm writing a utility that is going to be run on a large, random set of linux machines, and I'd like that utility to automatically figure out the MX hosts that will actually be used on each machine when mail
or mailx
are used.
I know I can look at the machine's mail server's config file to see what the setting is for outgoing email, but each host might be using a different email server (sendmail
, postfix
, exim
, etc.), and I don't want to write a utility that searches for each one and then tries to parse whatever config files it might find.
If I knew the algorithm that mail
and mailx
use for deciding what server to use for outgoing mail, I could then replicate that algorithm within my own utility.
Do mail
and mailx
just try 127.0.0.1
? Or do they do something like getting the current host name and then using a DNS query to find the MX records for that host, or if none exist, to use the info from the A record? Or do they simply use the sendmail
program (in which case, I'd need to figure out which outgoing server that sendmail
chooses)? ... or what?
Thank you very much.