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.
Example
package main
import (
"fmt"
"net"
)
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
How do you create an HTTP server in Go?
Convert Float32 to Float64 and Float64 to Float32
How to convert Struct fields into Map String?
How to use WaitGroup to delay execution of the main function until after all goroutines are complete.
How to Convert string to float type in Go?
Go program to find TXT records of a domain