Documentation
¶
Overview ¶
Package mail sends email, written as Svelte components in src/emails:
mailer := mail.New(mail.SMTP{Host: "smtp.example.com", Port: 587, Username: user, Password: pass}, "Acme <hello@acme.com>")
msg, err := mailer.Template(ctx, app, "Welcome", map[string]any{"name": u.Name, "link": confirmURL})
msg.To = []string{u.Email}
err = mailer.Send(ctx, msg)
Under tern dev, use mail.Log to print messages instead of sending them. To send in the background with retries, use Job with a jobs queue:
sendMail := mail.Job(q, mailer) _, err = sendMail.Enqueue(ctx, *msg)
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Log ¶
Log prints messages instead of sending them, for development. It keeps the last 50 for tests to inspect.
type Mailer ¶
type Mailer struct {
// contains filtered or unexported fields
}
Mailer builds and sends messages.
type Message ¶
type Message struct {
From string `json:"from,omitempty"` // the Mailer's default when empty
To []string `json:"to"`
Cc []string `json:"cc,omitempty"`
Bcc []string `json:"bcc,omitempty"`
ReplyTo string `json:"replyTo,omitempty"`
Subject string `json:"subject"`
HTML string `json:"html,omitempty"`
Text string `json:"text,omitempty"`
// Headers are extra headers, such as List-Unsubscribe.
Headers map[string]string `json:"headers,omitempty"`
}
Message is an email.
type SMTP ¶
type SMTP struct {
Host string
Port int
Username string
Password string
// Insecure allows sending without TLS, such as to a local Mailpit.
Insecure bool
// Timeout bounds a delivery; the default is 30 seconds.
Timeout time.Duration
}
SMTP sends through an SMTP server. Port 465 uses implicit TLS; other ports upgrade with STARTTLS when the server offers it, which is required unless Insecure is set (for local test servers).
Click to show internal directories.
Click to hide internal directories.