-
Notifications
You must be signed in to change notification settings - Fork 0
/
mx.go
41 lines (38 loc) · 833 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
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package valmail
import (
"net"
)
func (e *EmailAddress) populateMX() error {
// don't re-populate if we already have records
if e.mxRecords != nil || len(e.mxRecords) > 0 {
return nil
}
// otherwise lets do an MX lookup for the domain
mxRecords, err := net.LookupMX(e.Domain)
if err != nil {
return err
}
// check if they are nil or zero length
if len(mxRecords) == 0 {
// this should never happen because populateMX should return "no such server"
return err
} else {
// if they exist store them in case we need them later
e.mxRecords = mxRecords
}
return nil
}
func (e *EmailAddress) MXValid() bool {
// can't validate if this isn't a real email
if !e.SyntaxValid {
return false
}
err := e.populateMX()
if err != nil {
return false
}
if len(e.mxRecords) > 0 {
return true
}
return false
}