Documentation ¶
Overview ¶
Package mailer is a functional wrapper around the standard "net/smtp" and "html/template" packages.
Index ¶
Constants ¶
const (
// GlobalHeaders is set on every message.
GlobalHeaders = "MIME-Version: 1.0\r\nContent-type: text/html; charset=\"UTF-8\"\r\n\r\n"
)
Variables ¶
var Debug bool
Debug mode prints the outgoing mail before sending
Functions ¶
This section is empty.
Types ¶
type Mailer ¶
type Mailer struct {
// contains filtered or unexported fields
}
Mailer holds a html template, server and authentication information for efficient reuse.
func New ¶
New returns a reusable mailer. Tmpl should hold a collection of parsed templates. Addr is the hostname and port used by smtp.SendMail. For example:
"mail.host.com:587"
From is used in every subsequent SendMail invocation and set as message header. If auth is nil, connections will omit authentication.
func (*Mailer) Send ¶
func (m *Mailer) Send(headers []Header, tmplName string, data interface{}, recipients ...string) error
Send renders the headers and named template with passed data. The rendered message is sent using smtp.SendMail, to all the recipients.
Headers keys are rendered Title cased, and the values are joined with a comma separator. Each entry becomes a CRLF separated line. For example:
{"to", []string{"test@test.mailu.io", "admin@test.mailu.io"}}
Results in:
To: test@test.mailu.io,admin@test.mailu.io
The current time is automatically appended as timestamp header.