evt

package module
v0.0.0-...-644ac84 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2022 License: MIT Imports: 21 Imported by: 0

README

evt

Email Verification Tool

Go library for email verification without sending emails

Install

go get github.com/pchchv/evt

Usage

package main

import (
    "fmt"
    "github.com/pchchv/evt"
)

var verifier = evt.NewVerifier()

func main() {
    email := "example@exampledomain.com"
    ret, err := verifier.Verify(email)
    if err != nil {
        fmt.Println("verify email address failed, error is: ", err)
        return
    }
    if !ret.Syntax.Valid {
        fmt.Println("email address syntax is invalid")
        return
    }
    fmt.Println("email validation result", ret)
}
Using SMTP
package main

import (
    "fmt"
    "github.com/pchchv/evt"
)

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

func main() {
    domain := "domain.org"
    username := "username"
    ret, err := verifier.CheckSMTP(domain, username)
    if err != nil {
        fmt.Println("check smtp failed: ", err)
        return
    }
    fmt.Println("smtp validation result: ", ret)
}
Using SOCKS5
package main

import (
    "fmt"
    "github.com/pchchv/evt"
)

var verifier = evt.NewVerifier().
    EnableSMTPCheck().
    Proxy("socks5://user:password@127.0.0.1:1080?timeout=5s")

func main() {
    domain := "domain.org"
    username := "username"
    ret, err := verifier.CheckSMTP(domain, username)
    if err != nil {
        fmt.Println("check smtp failed: ", err)
        return
    }
    fmt.Println("smtp validation result: ", ret)
}
Checking whether a domain is disposable
package main

import (
    "fmt"
    "github.com/pchchv/evt"
)

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

func main() {
    domain := "domain.org"
    if verifier.IsDisposable(domain) {
        fmt.Printf("%s is a disposable domain\n", domain)
        return
    }
    fmt.Printf("%s is not a disposable domain\n", domain)
}
Suggestions for domain typo
package main

import (
    "fmt"
    "github.com/pchchv/evt"
)

var verifier = evt.NewVerifier()

func main() {
    domain := "gmai.com"
    suggestion := verifier.SuggestDomain(domain) 
    // suggestion should be `gmail.com`
    if suggestion != "" {
        fmt.Printf("domain %s is misspelled, right domain is %s. \n", domain, suggestion)
        return 
    }
    fmt.Printf("domain %s has no possible misspellings. \n", domain)
}

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

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

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
}

Detail about the Gravatar

type LookupError

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

MX dns records lookup error

func ParseSMTPError

func ParseSMTPError(err error) *LookupError

Receives 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
}

Detail about the Mx host

type Result

type Result struct {
	Email        string    `json:"email"`          // Passed email address
	Reachable    string    `json:"reachable"`      // Enumeration to describe whether the recipient's address is real
	Syntax       Syntax    `json:"syntax"`         // Details about the email address syntax
	SMTP         *SMTP     `json:"smtp"`           // Details about the SMTP response of the email
	Gravatar     *Gravatar `json:"gravatar"`       // Whether there is a gravatar for email
	Suggestion   string    `json:"suggestion"`     // Suggesting a domain when the domain is misspelled
	Disposable   bool      `json:"disposable"`     // Disposable email address
	RoleAccount  bool      `json:"role_account"`   // Is the account role-based
	Free         bool      `json:"free"`           // Is domain a free email domain
	HasMxRecords bool      `json:"has_mx_records"` // Whether MX-Records for the domain
}

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 email the email server
	Disabled    bool `json:"disabled"`    // Is the email blocked or disabled by the provider
}

Stores all information for SMTP verification lookup

type Syntax

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

Stores all information about an email Syntax

type Verifier

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

Email verifier Create one by calling NewVerifier

func NewVerifier

func NewVerifier() *Verifier

Creates a new email verifier

func (*Verifier) AddDisposableDomains

func (v *Verifier) AddDisposableDomains(domains []string) *Verifier

Adds additional domains as disposable domains

func (*Verifier) CheckGravatar

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

Returns the Gravatar records for the given email

func (*Verifier) CheckMX

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

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)

Performs an email verification on the passed domain via SMTP

  • the domain is the passed email domain
  • username is used to check the deliverability of specific email address

if server is catch-all server, username will not be checked

func (*Verifier) DisableAutoUpdateDisposable

func (v *Verifier) DisableAutoUpdateDisposable() *Verifier

Stops previously started schedule job

func (*Verifier) DisableDomainSuggest

func (v *Verifier) DisableDomainSuggest() *Verifier

Will not suggest anything

func (*Verifier) DisableGravatarCheck

func (v *Verifier) DisableGravatarCheck() *Verifier

Disables check gravatar

func (*Verifier) DisableSMTPCheck

func (v *Verifier) DisableSMTPCheck() *Verifier

Disables check email by smtp

func (*Verifier) EnableAutoUpdateDisposable

func (v *Verifier) EnableAutoUpdateDisposable() *Verifier

Enables update disposable domains automatically

func (*Verifier) EnableDomainSuggest

func (v *Verifier) EnableDomainSuggest() *Verifier

Will uggest a most similar correct domain when domain misspelled

func (*Verifier) EnableGravatarCheck

func (v *Verifier) EnableGravatarCheck() *Verifier

Enables check gravatar, we don't check gravatar by default

func (*Verifier) EnableSMTPCheck

func (v *Verifier) EnableSMTPCheck() *Verifier

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

Sets the emails to use in the `MAIL FROM:` smtp command

func (*Verifier) HelloName

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

Sets the name to use in the `EHLO:` SMTP command

func (*Verifier) IsDisposable

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

Checks if the domain is disposable

func (*Verifier) IsFreeDomain

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

Checks if the domain is free

func (*Verifier) IsRoleAccount

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

Checks if username is a role-based account

func (*Verifier) ParseAddress

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

Attempts to parse an email address and return it in the form of a Syntax

func (*Verifier) Proxy

func (v *Verifier) Proxy(proxyURI string) *Verifier

Sets a SOCKS5 proxy to verify the email, proxyURI should be in the format: "socks5://user:password@127.0.0.1:1080?timeout=5s". The protocol could be socks5, socks4 and socks4a.

func (*Verifier) SuggestDomain

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

Checks if domain has a typo and suggests a similar correct domain from metadata, returns a suggestion

func (*Verifier) Verify

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

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