forked from AfterShip/email-verifier
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mx.go
22 lines (19 loc) · 536 Bytes
/
mx.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package emailverifier
import "net"
// Mx is detail about the Mx host
type Mx struct {
HasMXRecord bool // whether has 1 or more MX record
Records []*net.MX // represent DNS MX records
}
// CheckMX will return the DNS MX records for the given domain name sorted by preference.
func (v *Verifier) CheckMX(domain string) (*Mx, error) {
domain = domainToASCII(domain)
mx, err := net.LookupMX(domain)
if err != nil && len(mx) == 0 {
return nil, err
}
return &Mx{
HasMXRecord: len(mx) > 0,
Records: mx,
}, nil
}