Golang package for email validation.
- Format (simple regexp, see: https://www.w3.org/TR/html5/forms.html#valid-e-mail-address and https://davidcel.is/posts/stop-validating-email-addresses-with-regex/)
- Valid domain
- Valid user: verify if the user and mailbox really exist
Install the Checkmail package
go get github.com/badoux/checkmail
funcmain() {
err:=checkmail.ValidateFormat("ç$€§/az@gmail.com")
iferr!=nil {
fmt.Println(err)
}
}output: invalid format
funcmain() {
err:=checkmail.ValidateHost("email@x-unkown-domain.com")
iferr!=nil {
fmt.Println(err)
}
}output: unresolvable host
If host is valid, requires valid SMTP serverHostName (see to online validator) and serverMailAddress to reverse validation
for prevent SPAN and BOTS.
funcmain() {
var (
serverHostName="smtp.myserver.com"// set your SMTP server hereserverMailAddress="validuser@myserver.com"// set your valid mail address here
)
err:=checkmail.ValidateHostAndUser(serverHostName, serverMailAddress, "unknown-user-129083726@gmail.com")
ifsmtpErr, ok:=err.(checkmail.SmtpError); ok&&err!=nil {
fmt.Printf("Code: %s, Msg: %s", smtpErr.Code(), smtpErr)
}
}output: Code: 550, Msg: 550 5.1.1 The email account that you tried to reach does not exist.
Checkmail is licensed under the MIT License.
