email

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: AGPL-3.0 Imports: 22 Imported by: 0

Documentation

Overview

Package email sends reminders by email over SMTP (ADR 0007). It is a notify-only channel: the message carries the reminder and one button that opens the subscription in the web.

It uses the standard library (net/smtp, crypto/tls): one message per reminder to one recipient needs nothing more.

Index

Constants

View Source
const (
	TLSStartTLS = "starttls" // plain connection upgraded with STARTTLS (port 587)
	TLSImplicit = "tls"      // TLS from the first byte (port 465)
	TLSNone     = "none"     // no encryption: local relays only
)

TLS modes.

View Source
const Name = "email"

Name is the channel name in channel_links.

Variables

View Source
var ErrNotConfigured = errors.New("email is not set up")

ErrNotConfigured is returned while the owner has not set up SMTP.

Functions

func Address

func Address(raw string) (string, error)

Address validates an address a member typed and returns it in the form accounts use: bare (no display name) and lower case.

func Check

func Check(ctx context.Context, cfg Config) error

Check connects and signs in without sending anything, so a wrong setting shows when it is saved rather than when the first reminder is due.

func Send

func Send(ctx context.Context, cfg Config, to string, m Mail) error

Send delivers one message to one recipient.

Types

type Channel

type Channel struct {
	notify.OneWay
	// Config returns the current SMTP settings; ok is false while email is
	// not set up. It is read for every message, so a change applies at once.
	Config func(ctx context.Context) (cfg Config, ok bool)
	// PublicURL is the instance's public address ("" if unknown).
	PublicURL string
}

Channel is the email channel. Its chat id is the recipient's address.

func (*Channel) Name

func (c *Channel) Name() string

func (*Channel) Send

func (c *Channel) Send(ctx context.Context, to string, m actions.Message) (string, error)

Send emails the message to one address.

type Config

type Config struct {
	Host     string `json:"host"`
	Port     int    `json:"port"`
	Username string `json:"username,omitempty"`
	Password string `json:"password,omitempty"`
	// From is the sender: "reminders@example.com" or "Exhale <reminders@example.com>".
	From string `json:"from"`
	TLS  string `json:"tls"`
	// RootCAs replaces the system certificates (tests).
	RootCAs *x509.CertPool `json:"-"`
}

Config is how to reach the SMTP server.

func (Config) Normalize

func (c Config) Normalize() (Config, error)

Normalize trims the fields, fills the defaults (STARTTLS, the usual port of the TLS mode) and reports what is wrong with the rest.

type Mail

type Mail struct {
	Subject string
	Text    string
	HTML    string
}

Mail is one message with a plain-text and an HTML version.

Directories

Path Synopsis
Package smtptest is an in-process SMTP server for tests.
Package smtptest is an in-process SMTP server for tests.

Jump to

Keyboard shortcuts

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