Go program to find MX records record of a domain

These records identify the servers that can exchange emails. The net.LookupMX() function takes a domain name as a string and returns a slice of MX structs sorted by preference. An MX struct is made up of a Host as a string and Pref as a uint16.


package main
import (
func main() {
	mxrecords, _ := net.LookupMX("facebook.com")
	for _, mx := range mxrecords {
		fmt.Println(mx.Host, mx.Pref)

The output list MX record for the domain(facebook.com) followed by preference.

msgin.vvv.facebook.com. 10
Most Helpful This Week