Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/badoux/checkmail
Golang package for email validation
https://github.com/badoux/checkmail
format go golang host mail mailbox user validation
Last synced: 3 months ago
JSON representation
Golang package for email validation
- Host: GitHub
- URL: https://github.com/badoux/checkmail
- Owner: badoux
- License: mit
- Created: 2017-01-26T09:02:00.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2024-01-15T14:53:04.000Z (10 months ago)
- Last Synced: 2024-02-14T21:35:57.824Z (9 months ago)
- Topics: format, go, golang, host, mail, mailbox, user, validation
- Language: Go
- Homepage:
- Size: 26.4 KB
- Stars: 680
- Watchers: 11
- Forks: 90
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-discoveries - checkmail - email validator _(`Go`)_ (DevOps Utilities)
README
# checkmail
[Golang](http://golang.org/) 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[![GoDoc](https://godoc.org/github.com/badoux/checkmail?status.png)](https://godoc.org/github.com/badoux/checkmail)
## Usage
Install the Checkmail package
```
go get github.com/badoux/checkmail```
### 1. Format
```go
func main() {
err := checkmail.ValidateFormat("ç$€§/[email protected]")
if err != nil {
fmt.Println(err)
}
}
```
output: `invalid format`### 2. Domain
```go
func main() {
err := checkmail.ValidateHost("[email protected]")
if err != nil {
fmt.Println(err)
}
}
```
output: `unresolvable host`### 3. Host and User
If host is valid, requires valid SMTP `serverHostName` (see to [online validator](https://mxtoolbox.com/SuperTool.aspx)) and `serverMailAddress` to reverse validation
for prevent SPAN and BOTS.```go
func main() {
var (
serverHostName = "smtp.myserver.com" // set your SMTP server here
serverMailAddress = "[email protected]" // set your valid mail address here
)
err := checkmail.ValidateHostAndUser(serverHostName, serverMailAddress, "[email protected]")
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](./LICENSE).