Documentation
¶
Index ¶
- type Message
- type Option
- func WithBCC(recipients ...string) 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 WithSkipTLSVerify() Option
- func WithSubjectTemplate(tmpl *templates.StringTemplate) Option
- func WithTemplate(tmpl *templates.Template) Option
- func WithTo(recipients ...string) Option
- type Target
- 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 Option ¶
type Option func(*Target)
Option configures an email target.
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 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 ¶
WithTemplate configures the HTML email body template.
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 ¶
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) SendResult ¶
func (t *Target) SendResult(ctx context.Context, payload notify.Payload) (notify.DeliveryResult, error)
SendResult renders and sends an email notification with delivery details.