Help us shape the future of Go! Take the 2026 Go Developer Survey

mailer

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Overview

Package mailer sends email: the summary email. It is the only package that speaks SMTP. The in-memory fake for tests is in mailer/mailertest.

Index

Constants

View Source
const (
	StartTLS = "starttls"
	Implicit = "implicit"
	NoTLS    = "none"
)

TLS modes, as config.SMTPTLS spells them.

Variables

View Source
var (
	// ErrAuth means the mail server refused the user name or password.
	ErrAuth = errors.New("the mail server refused the user name or password")
	// ErrConnection means the mail server could not be reached, or the connection broke.
	ErrConnection = errors.New("could not reach the mail server")
	// ErrUnsupported means the server lacks what the settings require: STARTTLS, or a
	// sign-in method this package speaks.
	ErrUnsupported = errors.New("the mail server does not support what the settings require")
	// ErrTLS means the TLS handshake or the certificate check failed.
	ErrTLS = errors.New("the TLS handshake with the mail server failed")
	// ErrRefused means the server refused the sender, the recipient or the message.
	ErrRefused = errors.New("the mail server refused the email")
	// ErrAddress means an address in the message cannot be used.
	ErrAddress = errors.New("not a usable email address")
)

Sentinel errors. SMTP wraps them, so callers test with errors.Is.

Functions

func Compose

func Compose(from, to *mail.Address, m Message, now time.Time) ([]byte, error)

Compose writes m as an RFC 5322 message from one address to another: plain text, and with HTML a multipart/alternative of both, each quoted-printable in UTF-8.

Types

type Message

type Message struct {
	To      string // one address, with or without a display name
	Subject string
	Text    string
	HTML    string
}

Message is one email to one recipient. HTML is optional; Text is always sent.

type SMTP

type SMTP struct {
	Addr     string // host:port
	TLS      string // StartTLS, Implicit or NoTLS
	Username string // empty = no sign-in
	Password string
	From     string // the From header: an address, or "Name <address>"

	// TLSConfig is copied for each connection, with ServerName set to the host when it is
	// empty; nil checks the server's certificate against the system's roots.
	TLSConfig *tls.Config
	Timeout   time.Duration    // the whole send; 0 = 30 seconds
	Now       func() time.Time // the Date header; nil = time.Now
}

SMTP sends through one mail server. Credentials are used only on the wire.

func (*SMTP) Send

func (s *SMTP) Send(ctx context.Context, m Message) error

Send delivers m: dial, TLS as configured, sign in when a user name is set, then one MAIL, RCPT and DATA.

type Sender

type Sender interface {
	Send(ctx context.Context, m Message) error
}

Sender sends a message.

Directories

Path Synopsis
Package mailertest is an in-memory mailer.Sender for tests of the packages that send email.
Package mailertest is an in-memory mailer.Sender for tests of the packages that send email.

Jump to

Keyboard shortcuts

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