How do I query a DNS server for the MX (or other) records it holds on a domain?
Operating system libraries usually provide a way to find out the A records, e.g. gethostbyname() - this same functionality is in the java.net.InetAddress class in Java via getByName() and related methods. I've never encountered a system function to get the MX records, and the same is true in Java. To find the MX records you will need to open a socket to the DNS server and form a proper query. Refer to the above RFCs for details of the protocol.