Documentation
¶
Index ¶
- Constants
- func GenerateRandomEmail(domain string) string
- func IsAddressValid(email string) bool
- type Gravatar
- type LookupError
- type Mx
- type Result
- type SMTP
- type Syntax
- type Verifier
- func (v *Verifier) AddDisposableDomains(domains []string) *Verifier
- func (v *Verifier) CheckGravatar(email string) (*Gravatar, error)
- func (v *Verifier) CheckMX(domain string) (*Mx, error)
- func (v *Verifier) CheckSMTP(domain, username string) (*SMTP, error)
- func (v *Verifier) ConnectTimeout(timeout time.Duration) *Verifier
- func (v *Verifier) DisableAPIVerifier(name string)
- func (v *Verifier) DisableAutoUpdateDisposable() *Verifier
- func (v *Verifier) DisableCatchAllCheck() *Verifier
- func (v *Verifier) DisableDomainSuggest() *Verifier
- func (v *Verifier) DisableGravatarCheck() *Verifier
- func (v *Verifier) DisableSMTPCheck() *Verifier
- func (v *Verifier) EnableAPIVerifier(name string) error
- func (v *Verifier) EnableAutoUpdateDisposable() *Verifier
- func (v *Verifier) EnableCatchAllCheck() *Verifier
- func (v *Verifier) EnableDomainSuggest() *Verifier
- func (v *Verifier) EnableGravatarCheck() *Verifier
- func (v *Verifier) EnableSMTPCheck() *Verifier
- func (v *Verifier) FromEmail(email string) *Verifier
- func (v *Verifier) HelloName(domain string) *Verifier
- func (v *Verifier) IsDisposable(domain string) bool
- func (v *Verifier) IsFreeDomain(domain string) bool
- func (v *Verifier) IsRoleAccount(username string) bool
- func (v *Verifier) OperationTimeout(timeout time.Duration) *Verifier
- func (v *Verifier) ParseAddress(email string) Syntax
- func (v *Verifier) Proxy(proxyURI string) *Verifier
- func (v *Verifier) Resolver(resolver *net.Resolver) *Verifier
- func (v *Verifier) SuggestDomain(domain string) string
- func (v *Verifier) Verify(email string) (*Result, error)
Constants ¶
const ( // Standard Errors ErrTimeout = "The connection to the mail server has timed out" ErrNoSuchHost = "Mail server does not exist" 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 ¶
GenerateRandomEmail generates a random email address using the domain passed. Used primarily for checking the existence of a catch-all address
func IsAddressValid ¶
IsAddressValid checks if email address is formatted correctly by using regex
Types ¶
type Gravatar ¶
type Gravatar struct {
HasGravatar bool `json:"has_gravatar"` // whether has gravatar
// GravatarUrl keeps its non-idiomatic spelling because it is an exported
// field: renaming it to GravatarURL would break every caller.
GravatarUrl string `json:"gravatar_url"` //nolint:staticcheck // ST1003
}
Gravatar is detail about the Gravatar
type LookupError ¶
type LookupError struct {
Message string `json:"message" xml:"message"`
Details string `json:"details" xml:"details"`
// contains filtered or unexported fields
}
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.
A non-nil err always yields a non-nil result: an error we cannot classify is reported verbatim rather than discarded. Returning nil here would hand the caller a non-nil error interface wrapping a nil *LookupError, whose Error method then panics.
func (*LookupError) EnhancedCode ¶
func (e *LookupError) EnhancedCode() string
EnhancedCode returns the RFC 3463 enhanced status code the server sent, for example "5.7.1", or an empty string if it sent none. Several large providers send none, so callers must handle the empty case rather than read it as a classification.
The class digit is dependable -- 2 success, 4 transient, 5 permanent -- but the subject is evidence, not a verdict: providers disagree with the registry and with each other over which subject an unknown recipient gets.
func (*LookupError) Error ¶
func (e *LookupError) Error() string
func (*LookupError) Unwrap ¶
func (e *LookupError) Unwrap() error
Unwrap returns the error this LookupError was derived from, if any.
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
Reachable string `json:"reachable"` // an enumeration to describe whether the recipient 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 or not have gravatar for the email
Suggestion string `json:"suggestion"` // domain suggestion when domain is misspelled
Disposable bool `json:"disposable"` // is this a DEA (disposable email address)
RoleAccount bool `json:"role_account"` // is account a role-based account
Free bool `json:"free"` // is domain a free email domain
HasMxRecords bool `json:"has_mx_records"` // whether or not MX-Records for the domain
}
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 (*Verifier) AddDisposableDomains ¶
AddDisposableDomains adds additional domains as disposable domains.
func (*Verifier) CheckGravatar ¶
CheckGravatar will return the Gravatar records for the given email.
func (*Verifier) CheckMX ¶
CheckMX will return the DNS MX records for the given domain name sorted by preference.
func (*Verifier) CheckSMTP ¶
CheckSMTP 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) ConnectTimeout ¶
ConnectTimeout sets the timeout for establishing connections.
func (*Verifier) DisableAPIVerifier ¶
func (*Verifier) DisableAutoUpdateDisposable ¶
DisableAutoUpdateDisposable stops previously started schedule job
func (*Verifier) DisableCatchAllCheck ¶
DisableCatchAllCheck disables catchAll check by smtp
func (*Verifier) DisableDomainSuggest ¶
DisableDomainSuggest will not suggest anything
func (*Verifier) DisableGravatarCheck ¶
DisableGravatarCheck disables check gravatar,
func (*Verifier) DisableSMTPCheck ¶
DisableSMTPCheck disables check email by smtp
func (*Verifier) EnableAPIVerifier ¶
EnableAPIVerifier activates an API-based existence check for the given vendor. ** Please know ** that this is a tricky way (but relatively stable) to check if target vendor's email exists. If you use this feature in a production environment, please ensure that you have sufficient backup measures in place, as this may encounter rate limiting or other API issues.
There are currently no built-in vendors: the Yahoo verifier was removed once its endpoint stopped existing (see https://github.com/AfterShip/email-verifier/issues/195), following the same fate as the Gmail verifier removed in #113. This remains an extension point; contributions adding a working vendor are welcome.
func (*Verifier) EnableAutoUpdateDisposable ¶
EnableAutoUpdateDisposable enables update disposable domains automatically
func (*Verifier) EnableCatchAllCheck ¶
EnableCatchAllCheck enables the catchAll check by smtp. It is on by default; this undoes a previous DisableCatchAllCheck.
func (*Verifier) EnableDomainSuggest ¶
EnableDomainSuggest will suggest a most similar correct domain when domain misspelled
func (*Verifier) EnableGravatarCheck ¶
EnableGravatarCheck enables check gravatar, we don't check gravatar by default
func (*Verifier) EnableSMTPCheck ¶
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) IsDisposable ¶
IsDisposable checks if domain is a disposable domain
func (*Verifier) IsFreeDomain ¶
IsFreeDomain checks if domain is a free domain
func (*Verifier) IsRoleAccount ¶
IsRoleAccount checks if username is a role-based account
func (*Verifier) OperationTimeout ¶
OperationTimeout sets the timeout for SMTP operations (e.g., EHLO, MAIL FROM, etc.).
func (*Verifier) ParseAddress ¶
ParseAddress attempts to parse an email address and return it in the form of an Syntax
func (*Verifier) Proxy ¶
Proxy sets a SOCKS5 proxy to verify the email, proxyURI should be in the format: "socks5://user:password@127.0.0.1:1080".
The scheme must be socks5 or socks5h -- the only two golang.org/x/net/proxy resolves. Anything else, socks4 and socks4a included, fails the dial with "proxy: unknown scheme"; add it with proxy.RegisterDialerType.
Only the scheme, credentials and host are read; a query string is ignored, so a "?timeout=5s" has no effect. Use ConnectTimeout and OperationTimeout.
The proxy carries the connection to the mail server, not DNS: MX lookups still go out from the local machine. See Resolver for routing those through the proxy too.
func (*Verifier) Resolver ¶
Resolver sets a custom DNS resolver to use for MX and SMTP host lookups, allowing users to configure custom DNS servers instead of relying on the system's default resolver (e.g. /etc/resolv.conf). Passing nil restores the default resolver (net.DefaultResolver).
func (*Verifier) SuggestDomain ¶
SuggestDomain checks if domain has a typo and suggests a similar correct domain from metadata, returns a suggestion