Documentation
¶
Overview ¶
Package conn dials and authenticates IMAP and SMTP connections.
Index ¶
- Variables
- func DialIMAP(ctx context.Context, e Endpoint) (*imapclient.Client, error)
- func DialIMAPAbortable(ctx context.Context, e Endpoint, h *imapclient.UnilateralDataHandler) (*imapclient.Client, func(), error)
- func DialSMTP(ctx context.Context, e Endpoint) (*smtp.Client, error)
- func LogTrace(c *imapclient.Client, err error)
- func NewXOAuth2Client(username, token string) sasl.Client
- type Endpoint
- type FailureKind
- type Security
Constants ¶
This section is empty.
Variables ¶
var ClientVersion = "dev"
ClientVersion is sent in the IMAP ID command; release builds set it.
var ErrAuthFailed = errors.New("authentication failed")
ErrAuthFailed means the server rejected the credentials. Server text is never included, because servers may echo the submitted password.
var ErrSMTPAuthDisabled = errors.New("SMTP AUTH is disabled for the mailbox")
ErrSMTPAuthDisabled is an ErrAuthFailed whose server said SMTP AUTH is turned off for the mailbox (Microsoft's 535 5.7.139), not that the credentials are wrong.
var SystemProxy = sysproxy.For
SystemProxy is the proxy for a request to u, nil for none: the user's; tests stand in for it.
var TLSRoots *x509.CertPool
TLSRoots verifies servers' certificates, nil for the system's; tests stand in for it.
Functions ¶
func DialIMAPAbortable ¶
func DialIMAPAbortable(ctx context.Context, e Endpoint, h *imapclient.UnilateralDataHandler) (*imapclient.Client, func(), error)
DialIMAPAbortable is DialIMAP that also returns abort, which closes the network connection at once. Unlike Client.Close it does not wait for a response literal being read, so it can cut off a download. h, if not nil, receives unsolicited server updates (IDLE).
func DialSMTP ¶
DialSMTP connects to e and authenticates with PLAIN, or XOAUTH2 when e has an AccessToken.
func LogTrace ¶ added in v1.26.0
func LogTrace(c *imapclient.Client, err error)
LogTrace logs the end of c's traffic, masked, when err is a protocol error: a server response go-imap could not parse. The log is what an error report carries, so a report of such an error shows what the server sent.
func NewXOAuth2Client ¶
NewXOAuth2Client returns a SASL XOAUTH2 client (Google and Microsoft IMAP/SMTP).
Types ¶
type Endpoint ¶
type Endpoint struct {
Host string
Port int
Security Security
Username, Password string
AccessToken string
}
Endpoint describes one server and the credentials to use on it. A non-empty AccessToken selects XOAUTH2 and Password is ignored.
type FailureKind ¶
type FailureKind string
FailureKind is the broad cause of a failed dial, for diagnostics.
const ( FailureDNS FailureKind = "dns" FailureConnect FailureKind = "connect" FailureTimeout FailureKind = "timeout" FailureTLS FailureKind = "tls" FailureAuth FailureKind = "auth" FailureProtocol FailureKind = "protocol" FailureProxyUnreachable FailureKind = "proxy_unreachable" FailureProxyRefused FailureKind = "proxy_refused" FailureProxyAuth FailureKind = "proxy_auth" // the proxy's credentials, never the account's )
func Classify ¶
func Classify(err error) FailureKind
Classify maps an error from DialIMAP or DialSMTP to a FailureKind; nil gives "".