mail

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: MIT, MIT Imports: 6 Imported by: 1 module, 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 mail is how the session library sends mail: the invitation a tenant's administrator sends to an address, the link that verifies an address a person adds or changes, and the link a password sign-up starts from. The library writes to the Sender interface and knows nothing of the mail system behind it; an application configures a driver, the Google Workspace SMTP relay in mail/workspace, and hands it to the Auth. Every message is plain text with one link in it, from the one address the driver is configured to send as.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Log

type Log struct{}

Log is a Sender for development: it writes each message to the request's logger, link included, and sends nothing, so a developer follows the link from the log. Never for a deployed environment, where the links are secrets: there the application configures a driver.

func (Log) Send

func (Log) Send(ctx context.Context, msg Message) error

Send logs the message at Info.

type Message

type Message struct {
	// To is the recipient's address, one address with or without a display name
	// ("Ada Lovelace <ada@example.com>").
	To string
	// Subject is the subject line, in any language; the driver encodes it.
	Subject string
	// Text is the plain-text body, in any language.
	Text string
}

Message is one message to send: the recipient, the subject and the plain-text body. The sender's address and display name are the driver's settings, not the message's, so every message an application sends comes from the one address it is configured with.

func (*Message) Validate

func (m *Message) Validate() error

Validate refuses a message that cannot be sent: no recipient or one that is not an address, no subject, or no body.

type Recorder

type Recorder struct {

	// Sent holds the messages sent so far, in order.
	Sent []Message
	// Err, when set, is what Send answers after recording the message.
	Err error
	// contains filtered or unexported fields
}

Recorder is a Sender for tests: it keeps every message it was asked to send, in order, and answers Err when one is set. It is safe for concurrent use.

func (*Recorder) Fail added in v0.3.0

func (r *Recorder) Fail(err error)

Fail sets what Send answers from now on, nil for a sender that works again: a test that fails the sender part of the way through sets it here, under the recorder's lock.

func (*Recorder) Messages

func (r *Recorder) Messages() []Message

Messages answers a copy of what was sent so far.

func (*Recorder) Send

func (r *Recorder) Send(_ context.Context, msg Message) error

Send records the message and answers Err.

type Sender

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

Sender sends one message. A driver implements it over a mail system; the library calls it from the flows that send mail and reports its error to the person as the mail not having been sent, never with the system's own words.

Directories

Path Synopsis
Package workspace sends the session library's mail through the Google Workspace SMTP relay: a plain mail submission to smtp-relay.gmail.com on port 587 over TLS, which Google Cloud's compute products allow (they block port 25, the port a mail server of our own would need), authenticated as one mailbox of the organization's Workspace domain with an app password.
Package workspace sends the session library's mail through the Google Workspace SMTP relay: a plain mail submission to smtp-relay.gmail.com on port 587 over TLS, which Google Cloud's compute products allow (they block port 25, the port a mail server of our own would need), authenticated as one mailbox of the organization's Workspace domain with an app password.

Jump to

Keyboard shortcuts

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