This package implements classic, well known from PHP, method of sending emails. It's stupid simple and it works not only with Sendmail, but also with other MTAs, like Postfix or sSMTP, which provide compatibility 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,
- just uses
/usr/sbin/sendmail
command which is present on most of the systems,- if not, just update
sendmail.Binary
- if not, just update
- outputs emails to stdout when environment variable
DEBUG
is set.
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