Documentation
¶
Overview ¶
Package smtp sends email through any SMTP submission server, so the email provider (SendGrid, ZeptoMail, a self-hosted server, …) is configuration: host, port, username, password and the sender.
Port 465 is TLS from the first byte; any other port upgrades with STARTTLS when the server offers it, and must when credentials are sent to a host other than loopback. Each Send opens its own connection, so a Sender is safe for concurrent use. No error carries the password.
Index ¶
Constants ¶
const DefaultPort = 587
DefaultPort is the submission port used when Config.Port is 0.
const DefaultTimeout = 30 * time.Second
DefaultTimeout bounds one Send or CheckHealth when Config.Timeout is 0.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct {
Host string
// Port is 465 for implicit TLS, else STARTTLS; 0 is DefaultPort.
Port int
// Username and Password authenticate (PLAIN, else LOGIN); an empty
// Username sends without authenticating.
Username string
Password string
// From is the default sender, one RFC 5322 mailbox ("Name <a@b.example>"
// or "a@b.example"); a Message's From replaces it.
From string
// Timeout bounds one Send or CheckHealth; 0 is DefaultTimeout.
Timeout time.Duration
// TLS configures the TLS client (a private CA, a test server); nil uses
// the system roots. Its ServerName defaults to Host.
TLS *tls.Config
}
Config is an SMTP submission server and the default sender.
type Message ¶
type Message struct {
// From replaces Config.From for this message.
From *mail.Address
// To is one RFC 5322 mailbox.
To string
Subject string
Text string
HTML string
}
Message is one email to one recipient. It needs a subject and a text or HTML body (both send multipart/alternative).
type Sender ¶
type Sender struct {
// contains filtered or unexported fields
}
Sender delivers Messages through one SMTP server.
func (*Sender) CheckHealth ¶
CheckHealth connects, negotiates TLS and authenticates, then quits without sending: nil when the server would accept this Sender's mail.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package smtptest is an in-process SMTP server that captures what it is sent, so a test drives a real sender (helpers/smtp, or anything speaking SMTP) end to end and reads the delivered message back.
|
Package smtptest is an in-process SMTP server that captures what it is sent, so a test drives a real sender (helpers/smtp, or anything speaking SMTP) end to end and reads the delivered message back. |