Documentation
¶
Overview ¶
Package mail provides a fluent email API backed by go-mail (SMTP). HTML templates are rendered from Go's html/template package. Attachments, CC/BCC, and inline images are supported.
Index ¶
- func Send(ctx context.Context, m *Mailer, to, subject, tmpl string, data any) error
- type Config
- type LogTransport
- type Mailer
- type Message
- func (m *Message) Attach(path string) *Message
- func (m *Message) AttachReader(name string, r io.Reader) *Message
- func (m *Message) BCC(addrs ...string) *Message
- func (m *Message) CC(addrs ...string) *Message
- func (m *Message) Err() error
- func (m *Message) From(addr string) *Message
- func (m *Message) HTML(body string) *Message
- func (m *Message) Header(key, value string) *Message
- func (m *Message) Send() error
- func (m *Message) Subject(s string) *Message
- func (m *Message) Text(body string) *Message
- func (m *Message) To(addrs ...string) *Message
- func (m *Message) View(tmplName string, data any) *Message
- type SMTPTransport
- type Transport
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct {
Driver string // "smtp" | "log" (default: "smtp")
Host string
Port int
Username string
Password string
FromName string
FromAddr string
Encryption string // "tls", "starttls", "none" (default: "tls")
Timeout time.Duration
}
Config holds mail settings.
type LogTransport ¶
type LogTransport struct {
// contains filtered or unexported fields
}
LogTransport writes emails to a log file instead of sending them.
func (*LogTransport) Send ¶
func (l *LogTransport) Send(msg *Message) error
type Mailer ¶
type Mailer struct {
// contains filtered or unexported fields
}
Mailer manages message construction and delivery.
func NewFromConfig ¶
NewFromConfig creates a Mailer from oni.Config, reading all mail.* keys.
func (*Mailer) LoadTemplates ¶
LoadTemplates parses all *.html files in dir into the template set. Template names are relative paths, e.g. "welcome.html".
type Message ¶
type Message struct {
// contains filtered or unexported fields
}
Message is a fluent email message.
func (*Message) Attach ¶
Attach adds a file attachment by path. If the file cannot be opened the error is recorded and returned by Send() — the mail is never silently sent without its attachment. The file is closed after Send.
func (*Message) AttachReader ¶
AttachReader adds an attachment from an io.Reader.
func (*Message) Header ¶
Header adds a custom email header. Keys or values containing CR/LF are rejected (recorded as an error returned by Send) to block header injection.
func (*Message) Send ¶
Send delivers the message via the configured transport. Any error recorded while building the message (template failure, unreadable attachment, invalid header) aborts the send and is returned instead.
type SMTPTransport ¶
type SMTPTransport struct {
// contains filtered or unexported fields
}
SMTPTransport delivers via SMTP using go-mail.
func (*SMTPTransport) Send ¶
func (s *SMTPTransport) Send(msg *Message) error