validemail

package module
v0.0.0-...-d7ca5b7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 1, 2023 License: MIT Imports: 9 Imported by: 0

README

checkmail

Golang package for email validation.

GoDoc

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. Host and User

If host is valid, requires valid SMTP serverHostName (see to online validator) and serverMailAddress to reverse validation for prevent SPAN and BOTS.

func main() {
    var (
        serverHostName    = "smtp.myserver.com" // set your SMTP server here
        serverMailAddress = "validuser@myserver.com"  // set your valid mail address here
    )
    err := checkmail.ValidateHostAndUser(serverHostName, serverMailAddress, "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.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBadFormat        = errors.New("invalid format")
	ErrUnresolvableHost = errors.New("unresolvable host")
)

Functions

func DialTimeout

func DialTimeout(addr string, timeout time.Duration) (*smtp.Client, error)

DialTimeout returns a new Client connected to an SMTP server at addr. The addr must include a port, as in "mail.example.com:smtp".

func TestValidateFormat

func TestValidateFormat(t *testing.T)

func TestValidateHost

func TestValidateHost(t *testing.T)

func TestValidateHostAndUser

func TestValidateHostAndUser(t *testing.T)

func TestValidateMX

func TestValidateMX(t *testing.T)

func ValidateFormat

func ValidateFormat(email string) error

func ValidateHost

func ValidateHost(email string) error

ValidateHost validate mail host.

func ValidateHostAndUser

func ValidateHostAndUser(serverHostName, serverMailAddress, email string) error

ValidateHostAndUser validate mail host and user. If host is valid, requires valid SMTP [1] serverHostName and serverMailAddress to reverse validation for prevent SPAN and BOTS. [1] https://mxtoolbox.com/SuperTool.aspx

func ValidateMX

func ValidateMX(email string) error

ValidateMX validate if MX record exists for a domain.

Types

type SmtpError

type SmtpError struct {
	Err error
}

func NewSmtpError

func NewSmtpError(err error) SmtpError

func (SmtpError) Code

func (e SmtpError) Code() string

func (SmtpError) Error

func (e SmtpError) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL