This package implements the classic method of sending emails, well known from PHP. It's stupid simple and it works not only with Sendmail, but also with other MTAs, like Postfix, sSMTP, or mhsendmail, which provide a compatible interface.
- it separates email headers from email body,
- encodes UTF-8 headers like
Subject
,From
,To
- makes it easy to use text/template
- doesn't require any SMTP configuration,
- can write email body to a custom
io.Writer
to simplify testing - by default, it just uses
/usr/sbin/sendmail
(but can be changed if need be)
go get -u github.com/meehow/sendmail
package main
import (
"io"
"log"
"net/mail"
"github.com/meehow/sendmail"
)
func main() {
sm := sendmail.Mail{
Subject: "Cześć",
From: &mail.Address{"Michał", "[email protected]"},
To: []*mail.Address{
{"Ktoś", "[email protected]"},
{"Ktoś2", "[email protected]"},
},
}
io.WriteString(&sm.Text, ":)\r\n")
if err := sm.Send(); err != nil {
log.Println(err)
}
}
Instead of io.WriteString
, you can execute a template:
tpl := template.Must(template.New("email").Parse(`Hello {{.Name}}!`))
tpl.ExecuteTemplate(&sm.Text, "email", &struct{ Name string }{"Dominik"})
- HTML emails
- multipart emails (HTML + Text)
- attachments
- inline attachments