email

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: Apache-2.0 Imports: 24 Imported by: 2 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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BodyFormat added in v0.6.0

type BodyFormat string

BodyFormat selects the MIME representation of the rendered email body.

const (
	// BodyHTML sends the rendered body as text/html.
	BodyHTML BodyFormat = "html"
	// BodyText sends the rendered body as text/plain.
	BodyText BodyFormat = "text"
)

type Message

type Message struct {
	Subject string
	Body    string
}

Message contains a rendered email subject and body.

type OperationError added in v0.6.0

type OperationError struct {
	// Operation is the human-readable SMTP stage.
	Operation string
	// Timeout is the configured complete-attempt timeout.
	Timeout time.Duration
	// Err is the underlying transport or SMTP error.
	Err error
}

OperationError identifies the SMTP stage that failed while preserving the underlying cause.

func (*OperationError) Error added in v0.6.0

func (e *OperationError) Error() string

Error returns a concise operator-facing SMTP failure.

func (*OperationError) Unwrap added in v0.6.0

func (e *OperationError) Unwrap() error

Unwrap exposes the original cause for retry classification.

type Option

type Option func(*Target)

Option configures an email target.

func WithBCC

func WithBCC(recipients ...string) Option

WithBCC configures blind-carbon-copy envelope recipients.

func WithBodyFormat added in v0.6.0

func WithBodyFormat(format BodyFormat) Option

WithBodyFormat configures the rendered body's MIME format. The default is BodyHTML.

func WithCC

func WithCC(recipients ...string) Option

WithCC configures carbon-copy message recipients.

func WithCredentials

func WithCredentials(user, pass string) Option

WithCredentials configures SMTP username and password authentication.

func WithDialTimeout added in v0.0.8

func WithDialTimeout(timeout time.Duration) Option

WithDialTimeout configures the SMTP connection timeout.

func WithFrom

func WithFrom(from string) Option

WithFrom configures the envelope sender and message From header.

func WithHeader

func WithHeader(name, value string) Option

WithHeader configures one additional message header.

func WithHeaders

func WithHeaders(headers map[string]string) Option

WithHeaders configures additional message headers.

func WithHost

func WithHost(host string) Option

WithHost configures the SMTP server hostname or IP address.

func WithName

func WithName(name string) Option

WithName configures the human-readable target name used in logs.

func WithPort

func WithPort(port int) Option

WithPort configures the SMTP server port.

func WithProxyFromEnvironment added in v0.6.0

func WithProxyFromEnvironment() Option

WithProxyFromEnvironment makes SMTP delivery honor HTTP_PROXY, HTTPS_PROXY, and NO_PROXY.

func WithSkipTLSVerify

func WithSkipTLSVerify() Option

WithSkipTLSVerify disables SMTP STARTTLS certificate verification.

This should only be used for local development or trusted private SMTP servers with self-signed certificates.

func WithSubjectTemplate

func WithSubjectTemplate(tmpl *templates.StringTemplate) Option

WithSubjectTemplate configures the email subject template.

func WithTLSMode added in v0.2.0

func WithTLSMode(mode TLSMode) Option

WithTLSMode configures SMTP encryption. The default is TLSRequired.

func WithTemplate

func WithTemplate(tmpl templates.Renderer) Option

WithTemplate configures the email body template.

func WithTimeout added in v0.2.0

func WithTimeout(timeout time.Duration) Option

WithTimeout bounds the complete SMTP attempt (default 30 seconds).

func WithTo

func WithTo(recipients ...string) Option

WithTo configures primary message recipients.

type ProxyError added in v0.6.0

type ProxyError struct {
	// StatusCode is the HTTP response status returned by the proxy.
	StatusCode int
	// Status is the HTTP status text returned by the proxy.
	Status string
}

ProxyError reports a rejected HTTP CONNECT tunnel without exposing credentials.

func (*ProxyError) Error added in v0.6.0

func (e *ProxyError) Error() string

Error returns the proxy CONNECT failure.

type TLSMode added in v0.2.0

type TLSMode string

TLSMode selects how SMTP traffic is encrypted.

const (
	// TLSRequired requires STARTTLS and fails before sending if unavailable.
	TLSRequired TLSMode = "starttls"
	// TLSImplicit establishes TLS before the SMTP greeting (usually port 465).
	TLSImplicit TLSMode = "implicit"
	// TLSPlaintext explicitly disables TLS, for local or otherwise secured relays.
	TLSPlaintext TLSMode = "plaintext"
)

type Target

type Target struct {
	// TLSMode defaults to TLSRequired.
	TLSMode TLSMode
	// BodyFormat defaults to BodyHTML for backward compatibility.
	BodyFormat BodyFormat
	// Name is an optional human-readable target name used in logs.
	Name string

	// Host is the SMTP server hostname or IP address.
	Host string

	// Port is the SMTP server port. New defaults it to 587 when unset.
	Port int

	// User is the optional SMTP username used for authentication.
	User string

	// Pass is the optional SMTP password used for authentication.
	Pass string

	// From is the envelope sender and message From header.
	From string

	// To contains primary message recipients.
	To []string

	// CC contains carbon-copy message recipients.
	CC []string

	// BCC contains blind-carbon-copy envelope recipients.
	//
	// BCC recipients are passed to the SMTP server as envelope recipients, but
	// they are not written to the message headers.
	BCC []string

	// Headers contains additional message headers.
	//
	// Headers are appended in deterministic key order after the standard message
	// headers. Standard message headers such as From, To, Subject, MIME-Version,
	// and Content-Type cannot be overridden here.
	Headers map[string]string

	// SkipTLSVerify disables SMTP STARTTLS certificate verification.
	//
	// This should only be used for local development or trusted private SMTP
	// servers with self-signed certificates.
	SkipTLSVerify bool

	// DialTimeout limits how long SMTP connection establishment may take.
	//
	// New defaults DialTimeout to 10 seconds when unset.
	DialTimeout time.Duration
	// Timeout bounds the complete SMTP attempt, including TLS and message transfer.
	// Nonpositive values default to 30 seconds. An earlier caller deadline wins.
	Timeout time.Duration

	// ProxyFromEnvironment enables HTTP_PROXY, HTTPS_PROXY, and NO_PROXY for SMTP tunnels.
	ProxyFromEnvironment bool

	// Template renders the email body.
	Template templates.Renderer

	// SubjectTmpl renders the email subject.
	SubjectTmpl *templates.StringTemplate
}

Target delivers notifications via SMTP.

func New

func New(opts ...Option) *Target

New constructs an email target from options.

It applies SMTP defaults for optional fields:

  • Port defaults to 587.
  • DialTimeout defaults to 10 seconds.

Template and SubjectTmpl are not validated by New. They are rendered by Render, Validate, Send, or SendResult, which return errors for incomplete configuration.

The returned target is safe to pass to notify.Receiver.Targets.

func NewFromTarget

func NewFromTarget(target Target, opts ...Option) *Target

NewFromTarget constructs an email target from an existing Target value.

Additional options are applied after the initial target value, then defaults are filled in the same way as New.

func (*Target) ProxyAddress added in v0.6.0

func (t *Target) ProxyAddress() (string, error)

ProxyAddress returns the selected proxy authority without credentials.

func (*Target) Render

func (t *Target) Render(payload notify.Payload) (Message, error)

Render renders the configured subject and body templates.

func (*Target) Send

func (t *Target) Send(ctx context.Context, payload notify.Payload) (notify.DeliveryResult, error)

Send renders and sends an email notification.

func (*Target) SendResult

func (t *Target) SendResult(ctx context.Context, payload notify.Payload) (notify.DeliveryResult, error)

SendResult renders and sends an email notification with delivery details.

func (*Target) Type

func (t *Target) Type() string

Type returns the target type name.

func (*Target) Validate

func (t *Target) Validate(payload notify.Payload) error

Validate renders the target and validates SMTP settings without sending it.

Jump to

Keyboard shortcuts

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