Checkmail - Golang 简单库用于校验电子邮件
Checkmail - Golang 简单库用于校验电子邮件
Go 工具类
共505Star
详细介绍
checkmail
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
Usage
1. Format
func main() {
err := checkmail.ValidateFormat("ç$€§/az@gmail.com")
if err != nil {
fmt.Println(err)
}
}
output: invalid format
2. Domain
func main() {
err := checkmail.ValidateHost("email@x-unkown-domain.com")
if err != nil {
fmt.Println(err)
}
}
output: unresolvable host
3. User
func main() {
err := checkmail.ValidateHost("unknown-user-129083726@gmail.com")
if smtpErr, 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.
License
Checkmail is licensed under the MIT License.
-
581 Star
-
646 Star
-
1527 Star
-
0 Star
-
62 Star
-
143 Star
-
576 Star
-
3327 Star