Skip to content

Commit 6021f49

Browse files
Create separate function to just validate MX records
Some Cloud providers block port 25 in order to prevent email spam, so it might be useful to be able to validate MX records without validating connectivity to MX host.
1 parent 85ee8a7 commit 6021f49

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

checkmail.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ func ValidateFormat(email string) error {
4545
return nil
4646
}
4747

48+
// ValidateMX validate if MX record exists for a domain.
49+
func ValidateMX(email string) error {
50+
_, host := split(email)
51+
if _, err := net.LookupMX(host); err != nil {
52+
return ErrUnresolvableHost
53+
}
54+
55+
return nil
56+
}
57+
4858
// ValidateHost validate mail host.
4959
func ValidateHost(email string) error {
5060
_, host := split(email)

0 commit comments

Comments
 (0)