Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InitDefault ¶ added in v0.2.6
InitDefault creates the package-level default sender from cfg. A later successful call replaces the previous default.
Types ¶
type Config ¶ added in v0.2.6
type Config struct {
Host string // SMTP server host name
Port int // 465 = implicit TLS; any other port must offer STARTTLS
Username string // SMTP login
Password string // SMTP password
FromAddress string // sender address used when Message.From is empty
FromName string // optional display name of FromAddress
}
Config is the SMTP server and the default sender. email/component reads it from the email section of app.toml.
type Message ¶ added in v0.2.6
type Message struct {
From []string `json:"from,omitempty" validate:"omitempty,min=1,max=2"` // [0] sender address, [1] optional display name; empty = the sender of Config
To []string `json:"to,omitempty" validate:"required,min=1,dive,email"` // primary recipient addresses
Cc []string `json:"cc,omitempty" validate:"omitempty,dive,email"` // carbon-copy recipient addresses
Bcc []string `json:"bcc,omitempty" validate:"omitempty,dive,email"` // blind carbon-copy recipient addresses
Subject string `json:"subject,omitempty" validate:"omitempty,min=0,max=500"` // subject line
Body string `json:"body,omitempty"` // body text
ContentType string `json:"contentType,omitempty" validate:"omitempty,min=0,max=100"` // text/plain or text/html (default); parameters such as charset are ignored
}
Message is an outbound email: sender, recipients and content. Attachments are not supported. The validate tags are for validator.Validator() when the message comes from a request body.
type SMTPSender ¶ added in v0.2.6
type SMTPSender struct {
// contains filtered or unexported fields
}
SMTPSender sends email through one SMTP server with github.com/wneessen/go-mail. It is safe for concurrent use.
func Default ¶ added in v0.2.6
func Default() *SMTPSender
Default returns the package-level default sender, or nil before InitDefault succeeds. Use NewSMTPSender for any other instance.
func NewSMTPSender ¶ added in v0.2.6
func NewSMTPSender(cfg Config) (*SMTPSender, error)
NewSMTPSender checks cfg and returns a sender for it. It does not connect: each Send opens its own connection.
func (*SMTPSender) Send ¶ added in v0.2.6
func (s *SMTPSender) Send(msg *Message) error
Send checks msg, builds the MIME message and sends it. An empty msg.From means the sender of the Config.