emailverifier

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2021 License: MIT Imports: 20 Imported by: 0

README ΒΆ

email-verifier

βœ‰οΈ A Go library for email verification without sending any emails.

Build Status Godoc Coverage Status Go Report Card license

Features

  • Email Address Validation: validates if a string contains a valid email.
  • Email Verification Lookup via SMTP: performs an email verification on the passed email
  • MX Validation: checks the DNS MX records for the given domain name
  • Misc Validation: including Free email provider check, Role account validation, Disposable emails address (DEA) validation
  • Email Reachability: checks how confident in sending an email to the address

Install

Use go get to install this package.

go get -u github.com/AfterShip/email-verifier

Usage

Basic usage

Use Verify method to verify an email address with different dimensions

package main

import (
    "fmt"

    "github.com/AfterShip/email-verifier"
)

var (
    verifier = emailverifier.NewVerifier()
)

func main() {

    email := "example@exampledomain.org"
    ret, err := verifier.Verify(email)
    if err != nil {
        fmt.Println("check email failed: ", err)
        return
    }

    fmt.Println("email validation result", ret)
}
Email verification Lookup

Use CheckSMTP to performs an email verification lookup via SMTP.

var (
    verifier = emailverifier.
        NewVerifier().
        EnableSMTPCheck()
)

func main() {

    domain := "domain.org"
    ret, err := verifier.CheckSMTP(domain)
    if err != nil {
        fmt.Println("check smtp failed: ", err)
        return
    }

    fmt.Println("smtp validation result: ", ret)

}

Note: because most of the ISPs block outgoing SMTP requests through port 25 to prevent email spamming, the module will not perform SMTP checking by default. You can initialize the verifier with EnableSMTPCheck() to enable such capability if port 25 is usable.

Misc Validation

To check if an email domain is disposable via IsDisposable

var (
    verifier = emailverifier.
        NewVerifier().
        EnableAutoUpdateDisposable()
)

func main() {
    domain := "domain.org"
    ret := verifier.IsDisposable(domain)
    fmt.Println("misc validation result: ", ret)
}

Note: It is possible to automatically update the disposable domains daily by initializing verifier with EnableAutoUpdateDisposable()

For more detailed documentation, please check on godoc.org πŸ‘‰ email-verifier

Similar Libraries Comparison

email-verifier trumail check-if-email-exists freemail
Features 〰️ 〰️ 〰️ 〰️
Disposable email address validation βœ… βœ…, but not available in free lib βœ… βœ…
Disposable address autoupdate βœ… πŸ€” ❌ ❌
Free email provider check βœ… βœ…, but not available in free lib ❌ βœ…
Role account validation βœ… ❌ βœ… ❌
Syntax validation βœ… βœ… βœ… ❌
Email reachability βœ… βœ… βœ… ❌
DNS records validation βœ… βœ… βœ… ❌
Email deliverability βœ… βœ… βœ… ❌
Mailbox disabled βœ… βœ… βœ… ❌
Full inbox βœ… βœ… βœ… ❌
Host exists βœ… βœ… βœ… ❌
Catch-all βœ… βœ… βœ… ❌
Gravatar βœ… βœ…, but not available in free lib ❌ ❌
Typo check πŸ”œ βœ…, but not available in free lib ❌ ❌
Honeyport dection πŸ”œ ❌ ❌ ❌
Bounce email check πŸ”œ ❌ ❌ ❌
Tech 〰️ 〰️ 〰️ 〰️
Provide API πŸ”œ βœ… βœ… ❌
Free API πŸ”œ ❌ ❌ ❌
Language Go Go Rust JavaScript
Active maintain βœ… ❌ βœ… βœ…
High Performance βœ… ❌ βœ… βœ…

FAQ

The library hangs/takes a long time after 30 seconds when performing email verification lookup via SMTP

Most ISPs block outgoing SMTP requests through port 25 to prevent email spamming. email-verifier needs to have this port open to make a connection to the email's SMTP server. With the port being blocked, it is not possible to perform such checking, and it will instead hang until timeout error. Unfortunately, there is no easy workaround for this issue.

For more information, you may also visit this StackOverflow thread.

The output shows "connection refused" in the smtp.error field.

This error can also be due to SMTP ports being blocked by the ISP, see the above answer.

What does reachable: "unknown" means

This means that the server does not allow real-time verification of an email right now, or the email provider is a catch-all email server.

Credits

Contributing

For details on contributing to this repository, see the contributing guide.

License

This package is licensed under MIT license. See LICENSE for details.

Documentation ΒΆ

Index ΒΆ

Constants ΒΆ

View Source
const (
	// Standard Errors
	ErrTimeout           = "The connection to the mail server has timed out"
	ErrNoSuchHost        = "Mail server does not exist"
	ErrServerUnavailable = "Mail server is unavailable"
	ErrBlocked           = "Blocked by mail server"

	// RCPT Errors
	ErrTryAgainLater           = "Try again later"
	ErrFullInbox               = "Recipient out of disk space"
	ErrTooManyRCPT             = "Too many recipients"
	ErrNoRelay                 = "Not an open relay"
	ErrMailboxBusy             = "Mailbox busy"
	ErrExceededMessagingLimits = "Messaging limits have been exceeded"
	ErrNotAllowed              = "Not Allowed"
	ErrNeedMAILBeforeRCPT      = "Need MAIL before RCPT"
	ErrRCPTHasMoved            = "Recipient has moved"
)

Variables ΒΆ

This section is empty.

Functions ΒΆ

func GenerateRandomEmail ΒΆ

func GenerateRandomEmail(domain string) string

GenerateRandomEmail generates a random email address using the domain passed. Used primarily for checking the existence of a catch-all address

func IsAddressValid ΒΆ

func IsAddressValid(email string) bool

IsAddressValid checks if email address is formatted correctly by using regex

Types ΒΆ

type Gravatar ΒΆ

type Gravatar struct {
	HasGravatar bool   // whether has gravatar
	GravatarUrl string // gravatar url
}

Gravatar is detail about the Gravatar

type LookupError ΒΆ

type LookupError struct {
	Message string `json:"message" xml:"message"`
	Details string `json:"details" xml:"details"`
}

LookupError is an MX dns records lookup error

func ParseSMTPError ΒΆ

func ParseSMTPError(err error) *LookupError

ParseSMTPError receives an MX Servers response message and generates the corresponding MX error

func (*LookupError) Error ΒΆ

func (e *LookupError) Error() string

type Mx ΒΆ

type Mx struct {
	HasMXRecord bool      // whether has 1 or more MX record
	Records     []*net.MX // represent DNS MX records
}

Mx is detail about the Mx host

type Result ΒΆ

type Result struct {
	Email        string    `json:"email"`          // passed email address
	Disposable   bool      `json:"disposable"`     // is this a DEA (disposable email address)
	Reachable    string    `json:"reachable"`      // an enumeration to describe whether the recipient address is real
	RoleAccount  bool      `json:"role_account"`   // is account a role-based account
	Free         bool      `json:"free"`           // is domain a free email domain
	Syntax       *Syntax   `json:"syntax"`         // details about the email address syntax
	HasMxRecords bool      `json:"has_mx_records"` // whether or not MX-Records for the domain
	SMTP         *SMTP     `json:"smtp"`           // details about the SMTP response of the email
	Gravatar     *Gravatar `json:"gravatar"`       // whether or not have gravatar for the email
}

Result is the result of Email Verification

type SMTP ΒΆ

type SMTP struct {
	HostExists  bool `json:"host_exists"` // is the host exists?
	FullInbox   bool `json:"full_inbox"`  // is the email account's inbox full?
	CatchAll    bool `json:"catch_all"`   // does the domain have a catch-all email address?
	Deliverable bool `json:"deliverable"` // can send an email to the email server?
	Disabled    bool `json:"disabled"`    // is the email blocked or disabled by the provider?
}

SMTP stores all information for SMTP verification lookup

type Syntax ΒΆ

type Syntax struct {
	Username string `json:"username"`
	Domain   string `json:"domain"`
	Valid    bool   `json:"valid"`
}

Syntax stores all information about an email Syntax

type Verifier ΒΆ

type Verifier struct {
	// contains filtered or unexported fields
}

Verifier is an email verifier. Create one by calling NewVerifier

func NewVerifier ΒΆ

func NewVerifier() *Verifier

NewVerifier creates a new email verifier

func (*Verifier) CheckGravatar ΒΆ

func (v *Verifier) CheckGravatar(email string) (*Gravatar, error)

CheckGravatar will return the Gravatar records for the given email.

func (*Verifier) CheckMX ΒΆ

func (v *Verifier) CheckMX(domain string) (*Mx, error)

CheckMX will return the DNS MX records for the given domain name sorted by preference.

func (*Verifier) CheckSMTP ΒΆ

func (v *Verifier) CheckSMTP(domain, username string) (*SMTP, error)

CheckSMTP performs an email verification on the passed domain via SMTP

func (*Verifier) DisableAutoUpdateDisposable ΒΆ

func (v *Verifier) DisableAutoUpdateDisposable() *Verifier

DisableAutoUpdateDisposable stops previously started schedule job

func (*Verifier) DisableGravatarCheck ΒΆ

func (v *Verifier) DisableGravatarCheck() *Verifier

DisableGravatarCheck disables check gravatar,

func (*Verifier) DisableSMTPCheck ΒΆ

func (v *Verifier) DisableSMTPCheck() *Verifier

DisableSMTPCheck disables check email by smtp

func (*Verifier) EnableAutoUpdateDisposable ΒΆ

func (v *Verifier) EnableAutoUpdateDisposable() *Verifier

EnableAutoUpdateDisposable enables update disposable domains automatically

func (*Verifier) EnableGravatarCheck ΒΆ

func (v *Verifier) EnableGravatarCheck() *Verifier

EnableGravatarCheck enables check gravatar, we don't check gravatar by default

func (*Verifier) EnableSMTPCheck ΒΆ

func (v *Verifier) EnableSMTPCheck() *Verifier

EnableSMTPCheck enables check email by smtp, for most ISPs block outgoing SMTP requests through port 25, to prevent spam, we don't check smtp by default

func (*Verifier) FromEmail ΒΆ

func (v *Verifier) FromEmail(email string) *Verifier

FromEmail sets the emails to use in the `MAIL FROM:` smtp command

func (*Verifier) HelloName ΒΆ

func (v *Verifier) HelloName(domain string) *Verifier

HelloName sets the name to use in the `EHLO:` SMTP command

func (*Verifier) IsDisposable ΒΆ

func (v *Verifier) IsDisposable(domain string) bool

IsDisposable checks if domain is a disposable domain

func (*Verifier) IsFreeDomain ΒΆ

func (v *Verifier) IsFreeDomain(domain string) bool

IsFreeDomain checks if domain is a free domain

func (*Verifier) IsRoleAccount ΒΆ

func (v *Verifier) IsRoleAccount(username string) bool

IsRoleAccount checks if username is a role-based account

func (*Verifier) ParseAddress ΒΆ

func (v *Verifier) ParseAddress(email string) *Syntax

ParseAddress attempts to parse an email address and return it in the form of an Syntax

func (*Verifier) Verify ΒΆ

func (v *Verifier) Verify(email string) (*Result, error)

Verify performs address, misc, mx and smtp checks

Jump to

Keyboard shortcuts

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