Skip to content
This repository has been archived by the owner on May 24, 2024. It is now read-only.

Commit

Permalink
LookupMX is not reliable
Browse files Browse the repository at this point in the history
Signed-off-by: Łukasz Gryglicki <[email protected]>
  • Loading branch information
lukaszgryglicki committed Sep 2, 2021
1 parent 2922f45 commit 02732f2
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions email.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"regexp"
"strings"
"sync"
"time"
)

var (
Expand Down Expand Up @@ -57,11 +58,21 @@ func IsValidDomain(domain string) (valid bool) {
emailsCacheMtx.Unlock()
}
}()
mx, err := net.LookupMX(domain)
if err != nil || len(mx) == 0 {
return
for i := 0; i < 10; i++ {
mx, err := net.LookupMX(domain)
if err == nil && len(mx) > 0 {
valid = true
return
}
}
for i := 1; i <= 3; i++ {
mx, err := net.LookupMX(domain)
if err == nil && len(mx) > 0 {
valid = true
return
}
time.Sleep(time.Duration(i) * time.Second)
}
valid = true
return
}

Expand Down

0 comments on commit 02732f2

Please sign in to comment.