Mailer (Email)
core.IMailer — SMTP email over go-mail.
Setup
go
mailer, err := core.NewMailer(env)Configuration:
EMAIL_SERVER=smtp.example.com
EMAIL_PORT=587
EMAIL_USERNAME=...
EMAIL_PASSWORD=...
[email protected]Sending
go
err := mailer.Send(core.EmailMessage{
To: []string{"[email protected]"},
Cc: []string{"[email protected]"},
Subject: "Welcome",
HTML: "<h1>Hello</h1><p>Thanks for signing up.</p>",
Text: "Hello — thanks for signing up.", // plain-text fallback
})Provide HTML, Text, or both (both are attached as a multipart alternative).
Types
go
type EmailMessage struct {
To []string
Cc []string
Bcc []string
Subject string
HTML string
Text string
}
type IMailer interface {
Send(msg EmailMessage) IError
}
NewMaileruses PLAIN SMTP auth over STARTTLS on the configured port. The sender is taken fromEMAIL_SENDER.