1
0
mirror of https://github.com/muety/wakapi.git synced 2023-08-10 21:12:56 +03:00

chore: validate email addresses with dns

This commit is contained in:
Ferdinand Mütsch
2023-01-02 15:14:49 +01:00
parent ef5b49ebd8
commit a1444bca8c
4 changed files with 75 additions and 2 deletions

16
utils/dns.go Normal file
View File

@@ -0,0 +1,16 @@
package utils
import (
"net"
"strings"
)
// CheckEmailMX takes an e-mail address and verifies that an MX DNS record exists for its domain
func CheckEmailMX(email string) bool {
parts := strings.Split(email, "@")
if len(parts) != 2 {
return false
}
records, err := net.LookupMX(parts[1])
return len(records) > 0 && err == nil
}