mailck

package module
v0.0.0-...-0d8265f Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2021 License: MIT Imports: 6 Imported by: 11

README

mailck - SMTP mail validation

golang library for email validation

Build Status Go Report Card Coverage Status

This library allows you to check if an email address is realy valid:

  • Syntax check
  • Blacklist of disposable mailservers (e.g. mailinator.com)
  • SMTP mailbox check

Preconditions

Make sure, that the ip address you are calling from is not black listed. This is e.g. the case if the ip is a dynamic IP. Also make sure, that you have a correct reverse dns lookup for your ip address, matching the hostname of your from adress. Alternatively use a SPF DNS record entry matching the host part of the from address.

In case of a blacklisting, the target mailserver may respond with an SMTP 554 or just let you run into a timout.

Usage

GoDoc

Do all checks at once:

result, _ := mailck.Check("noreply@mancke.net", "foo@example.com")
switch {

  case result.IsValid():
  // valid!
  // the mailserver accepts mails for this mailbox.

  case result.IsError():
  // something went wrong in the smtp communication
  // we can't say for sure if the address is valid or not

  case result.IsInvalid():
  // invalid for some reason
  // the reason is contained in result.ResultDetail
  // or we can check for different reasons:
  switch (result) {
    case mailck.InvalidDomain:
    // domain is invalid
    case mailck.InvalidSyntax:
    // e-mail address syntax is invalid
  }
}

License

MIT Licensed

Documentation

Index

Constants

View Source
const (
	ValidState   ResultState = "valid"
	InvalidState             = "invalid"
	ErrorState               = "error"
)

Variables

View Source
var (
	Valid              = Result{ValidState, "mailboxChecked", "The email address is valid."}
	InvalidSyntax      = Result{InvalidState, "invalidSyntax", "The email format is invalid."}
	InvalidDomain      = Result{InvalidState, "invalidDomain", "The email domain does not exist."}
	MailboxUnavailable = Result{InvalidState, "mailboxUnavailable", "The email username does not exist."}
	Disposable         = Result{InvalidState, "disposable", "The email is a throw-away address."}
	MailserverError    = Result{ErrorState, "mailserverError", "The target mailserver responded with an error."}
	TimeoutError       = Result{ErrorState, "timeoutError", "The connection with the mailserver timed out."}
	NetworkError       = Result{ErrorState, "networkError", "The connection to the mailserver could not be made."}
	ServiceError       = Result{ErrorState, "serviceError", "An internal error occured while checking."}
	ClientError        = Result{ErrorState, "clientError", "The request was was invalid."}
)
View Source
var DisposableDomains = map[string]bool{}/* 1559 elements not displayed */

DisposableDomains is a list of fake mail providers. The list was taken from https://github.com/andreis/disposable License: MIT Last updated: Sa 4. Mär 21:33:31 CET 2017

Functions

func CheckDisposable

func CheckDisposable(checkEmail string) bool

CheckDisposable returns true if the mail is a disposal mail, false otherwise

func CheckSyntax

func CheckSyntax(checkEmail string) bool

CheckSyntax returns true for a valid email, false otherwise

Types

type Result

type Result struct {
	Result       ResultState `json:"result"`
	ResultDetail string      `json:"resultDetail"`
	Message      string      `json:"message"`
}

Result contains the information about an email check.

func Check

func Check(fromEmail, checkEmail string) (result Result, err error)

Check checks the syntax and if valid, it checks the mailbox by connecting to the target mailserver The fromEmail is used as from address in the communication to the foreign mailserver.

func CheckMailbox

func CheckMailbox(fromEmail, checkEmail string) (result Result, err error)

CheckMailbox checks the checkEmail by connecting to the target mailbox and returns the result. The fromEmail is used as from address in the communication to the foreign mailserver.

func CheckMailboxWithContext

func CheckMailboxWithContext(ctx context.Context, fromEmail, checkEmail string) (result Result, err error)

func CheckWithContext

func CheckWithContext(ctx context.Context, fromEmail, checkEmail string) (result Result, err error)

func (Result) IsError

func (r Result) IsError() bool

func (Result) IsInvalid

func (r Result) IsInvalid() bool

func (Result) IsValid

func (r Result) IsValid() bool

type ResultState

type ResultState string

func (ResultState) String

func (rs ResultState) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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