providers

package
v0.167.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 30, 2026 License: Apache-2.0 Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

View Source
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.

View Source
var LookupTimeout = 3 * time.Second

LookupTimeout bounds each discovery step: the MX lookup, the SRV lookups and each autoconfig fetch.

View Source
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.

View Source
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

func Guess(ctx context.Context, email string) Settings

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL