Documentation
¶
Overview ¶
Package providers knows the server settings of common mail hosts, so adding an account is an address and a password. Past the built-in table it asks only the user's own domain: its MX, its RFC 6186 SRV records and its own autoconfig file. No third-party directory is ever asked.
Index ¶
Constants ¶
const ( SourcePreset = "preset" // the address's domain is in the table SourceMX = "mx" // the domain's MX points at a host in the table SourceSRV = "srv" // the domain's RFC 6186 SRV records SourceAutoconfig = "autoconfig" // the domain's own config-v1.1.xml SourceGuess = "guess" // imap.<domain> / smtp.<domain>, unverified )
Where a Settings answer came from.
Variables ¶
var HTTPClient = &http.Client{}
HTTPClient fetches a domain's autoconfig file; replaced in tests. It follows a redirect only within the user's own domain (see sameDomain), so the address never reaches a third party.
var LookupTimeout = 3 * time.Second
LookupTimeout bounds each discovery step: the MX lookup, the SRV lookups and each autoconfig fetch.
var MXLookup = func(ctx context.Context, domain string) ([]string, error) { mx, err := net.DefaultResolver.LookupMX(ctx, domain) if err != nil { return nil, err } out := make([]string, len(mx)) for i, m := range mx { out[i] = strings.TrimSuffix(strings.ToLower(m.Host), ".") } return out, nil }
MXLookup resolves MX hosts; replaced in tests.
var SRVLookup = func(ctx context.Context, service, proto, domain string) ([]*net.SRV, error) { _, addrs, err := net.DefaultResolver.LookupSRV(ctx, service, proto, domain) return addrs, err }
SRVLookup resolves an RFC 6186 service record (`_service._proto.domain`); replaced in tests.
Functions ¶
This section is empty.
Types ¶
type Settings ¶
type Settings struct {
Provider string `json:"provider"`
IMAPHost string `json:"imap_host"`
IMAPPort int `json:"imap_port"`
IMAPTLS string `json:"imap_tls"`
SMTPHost string `json:"smtp_host"`
SMTPPort int `json:"smtp_port"`
SMTPTLS string `json:"smtp_tls"`
// Note tells the user what the host needs, e.g. an app password.
Note string `json:"note,omitempty"`
// HelpURL is the provider's own page for these settings.
HelpURL string `json:"help_url,omitempty"`
// Known is false when the settings are a guess.
Known bool `json:"known"`
// NeedsUsername: the sign-in name differs from the address (iCloud+
// custom domains, an autoconfig file that says so), so the form shows the
// Username field at once.
NeedsUsername bool `json:"needs_username,omitempty"`
// Username is the sign-in name when the domain's autoconfig names one.
Username string `json:"username,omitempty"`
// Source says how the answer was found; see the Source constants.
Source string `json:"source"`
}
Settings are the servers for an address.
func Guess ¶
Guess returns server settings for an address. In order: a known host by domain; a known host by the domain's MX record (a custom domain on Google Workspace, Microsoft 365, iCloud+, Zoho, a web host); the domain's RFC 6186 SRV records; the domain's own Thunderbird-format autoconfig file; and last the conventional imap./smtp. names. Every network question goes to the user's own domain or its DNS; no third-party directory is asked.