Socket
Book a DemoInstallSign in
Socket

github.com/faroffemerg/go-email-validator

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/faroffemerg/go-email-validator

v0.0.0-20250227031816-bb1633da2407
Source
Go
Version published
Created
Source

Go Reference codecov Go Report

Library under development (Interfaces may be changed slightly)

Demo on rapidapi.com

Install

go get -u github.com/faroffemerg/go-email-validator

Available validators

username@domain.part

Usage

With builder

package main

import (
  "fmt"
  "github.com/faroffemerg/go-email-validator/pkg/ev"
  "github.com/faroffemerg/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)
}

Single validator

package main

import (
  "fmt"
  "github.com/faroffemerg/go-email-validator/pkg/ev"
  "github.com/faroffemerg/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)
}

Addition options

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.

How to extend

To add own validator, just implement ev.Validator interface. For validator without dependencies, you can use structure ev.AValidatorWithoutDeps

Decorators

Notice, to use msgpack you should have exported fields or implement custom encoding/decoding (doc)

Logger

Package use zap.

To use logging see in log package. Default level is zap.ErrorLevel.

Addition

  • For running workflow locally use act

FAQ

Most Internet Service Providers block outgoing SMTP request.

The StackOverflow thread could be helpful.

To check smtp in telnet

telnet

OPEN gmail-smtp-in.l.google.com 25
EHLO localhost
MAIL FROM: <user@example.org>
rcpt to: <some.email@gmail.com>
quit

Some mail providers could put your ip in spam filter.

For example:

  • hotmail.com

Roadmap

  • 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

Inspired by

FAQs

Package last updated on 27 Feb 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.