email

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Message

type Message struct {
	Subject string
	Body    string
}

Message contains a rendered email subject and body.

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 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 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 WithTemplate

func WithTemplate(tmpl *templates.Template) Option

WithTemplate configures the HTML email body template.

func WithTo

func WithTo(recipients ...string) Option

WithTo configures primary message recipients.

type Target

type Target struct {
	// 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

	// Template renders the HTML email body.
	Template *templates.Template

	// 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) 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