Documentation
¶
Index ¶
- type BodyFormat
- type Message
- type OperationError
- type Option
- func WithBCC(recipients ...string) Option
- func WithBodyFormat(format BodyFormat) Option
- func WithCC(recipients ...string) Option
- func WithCredentials(user, pass string) Option
- func WithDialTimeout(timeout time.Duration) Option
- func WithFrom(from string) Option
- func WithHeader(name, value string) Option
- func WithHeaders(headers map[string]string) Option
- func WithHost(host string) Option
- func WithName(name string) Option
- func WithPort(port int) Option
- func WithProxyFromEnvironment() Option
- func WithSkipTLSVerify() Option
- func WithSubjectTemplate(tmpl *templates.StringTemplate) Option
- func WithTLSMode(mode TLSMode) Option
- func WithTemplate(tmpl templates.Renderer) Option
- func WithTimeout(timeout time.Duration) Option
- func WithTo(recipients ...string) Option
- type ProxyError
- type TLSMode
- type Target
- func (t *Target) ProxyAddress() (string, error)
- func (t *Target) Render(payload notify.Payload) (Message, error)
- func (t *Target) Send(ctx context.Context, payload notify.Payload) (notify.DeliveryResult, error)
- func (t *Target) SendResult(ctx context.Context, payload notify.Payload) (notify.DeliveryResult, error)
- func (t *Target) Type() string
- func (t *Target) Validate(payload notify.Payload) error
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 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 WithBodyFormat ¶ added in v0.6.0
func WithBodyFormat(format BodyFormat) Option
WithBodyFormat configures the rendered body's MIME format. The default is BodyHTML.
func WithCredentials ¶
WithCredentials configures SMTP username and password authentication.
func WithDialTimeout ¶ added in v0.0.8
WithDialTimeout configures the SMTP connection timeout.
func WithHeader ¶
WithHeader configures one additional message header.
func WithHeaders ¶
WithHeaders configures additional message headers.
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
WithTLSMode configures SMTP encryption. The default is TLSRequired.
func WithTemplate ¶
WithTemplate configures the email body template.
func WithTimeout ¶ added in v0.2.0
WithTimeout bounds the complete SMTP attempt (default 30 seconds).
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 ¶
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 ¶
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
ProxyAddress returns the selected proxy authority without credentials.
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.