Documentation
¶
Overview ¶
Package smtp provides an omnimail.Sender that delivers through an SMTP server (a relay such as Postfix, a provider's SMTP endpoint, or a local development server such as Mailpit).
It supports STARTTLS (default, required) and implicit TLS (SMTPS), AUTH PLAIN and LOGIN, dial and session timeouts, and context cancellation. Each Send uses its own connection, so a Sender is safe for concurrent use. Only the standard library is used.
s, err := smtp.New(smtp.Config{
Host: "email-smtp.us-east-1.amazonaws.com",
Username: user,
Password: pass,
})
Index ¶
Constants ¶
const ( DefaultDialTimeout = 10 * time.Second DefaultTimeout = 60 * time.Second )
Default timeouts.
const ProviderName = "smtp"
ProviderName is reported in SendResult.Provider and Error.Provider.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AuthMechanism ¶
type AuthMechanism string
AuthMechanism selects the SMTP AUTH mechanism.
const ( // AuthAuto picks PLAIN when the server offers it, otherwise LOGIN. AuthAuto AuthMechanism = "" // AuthPlain uses AUTH PLAIN (RFC 4616). AuthPlain AuthMechanism = "PLAIN" // AuthLogin uses AUTH LOGIN. AuthLogin AuthMechanism = "LOGIN" )
type Config ¶
type Config struct {
// Host is the server host name (required).
Host string
// Port defaults to 587 (StartTLS), 465 (ImplicitTLS) or 25 (Plaintext).
Port int
// Security defaults to StartTLS.
Security Security
// Username and Password enable SMTP AUTH when Username is set.
Username string
Password string
// Auth selects the mechanism (default AuthAuto).
Auth AuthMechanism
// AllowInsecureAuth permits sending credentials over an unencrypted
// connection. Off by default; enable only for local test servers.
AllowInsecureAuth bool
// TLSConfig customizes TLS. ServerName defaults to Host and MinVersion
// to TLS 1.2.
TLSConfig *tls.Config
// LocalName is the EHLO name (default "localhost").
LocalName string
// DialTimeout bounds connecting and the TLS handshake (default 10s).
DialTimeout time.Duration
// Timeout bounds a whole send session (default 60s). A shorter context
// deadline takes precedence.
Timeout time.Duration
// MessageIDDomain is the right-hand side of generated Message-IDs
// (default: the From domain).
MessageIDDomain string
// Dialer overrides the network dialer (default *net.Dialer).
Dialer Dialer
}
Config configures a Sender.
type Dialer ¶
type Dialer interface {
DialContext(ctx context.Context, network, address string) (net.Conn, error)
}
Dialer opens network connections. *net.Dialer implements it.
type Security ¶
type Security int
Security selects how the connection is encrypted.
const ( // StartTLS connects in plaintext and upgrades with STARTTLS. The upgrade // is required: if the server does not offer it, Send fails. Default port // 587. StartTLS Security = iota // ImplicitTLS uses TLS from the first byte (SMTPS). Default port 465. ImplicitTLS // Plaintext never encrypts. Use only for local relays and development // servers. Default port 25. Plaintext )
type Sender ¶
type Sender struct {
// contains filtered or unexported fields
}
Sender delivers messages over SMTP. It is safe for concurrent use.