go get -u github.com/prodadidb/go-email-validator
-
NewSyntaxValidator()
- mail.ParseAddress from built-in libraryNewSyntaxRegexValidator(emailRegex *regexp.Regexp)
- validation based on regular expression
-
disposableValidator based on mailchecker by default (set is replaceable)
-
roleValidator bases on role-based-email-addresses by default (set is replaceable)
-
to use proxy connection, DialFunc need to be changed in Checker. There is evsmtp.H12IODial, implementing for h12w.
-
banWordsUsernameValidator looks for banned words in username
-
blackListEmailsValidator blocked emails from list
-
blackListValidator blocked emails with domains from black list
-
whiteListValidator accepts only emails from white list
-
gravatarValidator check existing of user on gravatar.com
package main
import (
"fmt"
"github.com/prodadidb/go-email-validator/pkg/ev"
"github.com/prodadidb/go-email-validator/pkg/ev/evmail"
)
func main() {
// create defaults DepValidator with GetDefaultFactories() as list of validators
builder := ev.NewDepBuilder(nil).Build()
/*
to set another list of initial validators
builder := NewDepBuilder(&ValidatorMap{
ev.ValidatorName: ev.Validator,
}).Build()
*/
// builder.Set(ev.ValidatorName, NewValidator()) builder
// builder.Has(names ...ev.ValidatorName) bool
// builder.Delete(names ...ev.ValidatorName) bool
validator := builder.Build()
v := validator.Validate(NewInput(evmail.FromString("test@evmail.com")))
if !v.IsValid() {
panic("email is invalid")
}
fmt.Println(v)
}
package main
import (
"fmt"
"github.com/prodadidb/go-email-validator/pkg/ev"
"github.com/prodadidb/go-email-validator/pkg/ev/evmail"
)
func main() {
var v = ev.NewSyntaxValidator().Validate(ev.NewInput(evmail.FromString("some@evmail.here"))) // ev.ValidationResult
if !v.IsValid() {
panic("email is invalid")
}
fmt.Println(v)
}
To set options for different validators, use NewInput(..., NewKVOption(ValidatorName, Options))
NewInput(
evmail.FromString("test@evmail.com"),
NewKVOption(SMTPValidatorName, evsmtp.NewOptions(evsmtp.OptionsDTO{
Port: 465,
})),
)
Use function New...(...) to create structure instead of public.
To add own validator, just implement ev.Validator interface. For validator without dependencies, you can use structure ev.AValidatorWithoutDeps
- WarningsDecorator allows moving errors to warnings and change result of
IsValid()
in ValidationResult. - Cache based on evcahce.Interface, default realization is done for gocache.
- CacheDecorator saves result of validator. For caching, you can implement
evcache.Interface
or use gocache implementation byevcache.NewCache
. See Test_Cache as example. - checkerCacheRandomRCPT for caching of RandomRCPTs request. See Test_checkerCacheRandomRCPT_RandomRCPT_RealCache as example.
- CacheDecorator saves result of validator. For caching, you can implement
Notice, to use msgpack you should have exported fields or implement custom encoding/decoding (doc)
Package use zap.
To use logging see in log package. Default level is zap.ErrorLevel.
- For running workflow locally use act
The StackOverflow thread could be helpful.
telnet
OPEN gmail-smtp-in.l.google.com 25
EHLO localhost
MAIL FROM: <user@example.org>
rcpt to: <some.email@gmail.com>
quit
For example:
- hotmail.com
- Tests
- Add functional tests
- Find way to compare functions in tests
- Add binary release
- Check in spamhaus
- Add misspelled email
- Add DKIM checking
- Add linter in pre-hook and ci
- Do full thread safe library
- Copy features from truemail