repositorypackage
0.0.0-20191130200728-5f4e93383d51
Repository: https://github.com/casipw/email.git
Documentation: pkg.go.dev
# README
email

An easy way to send emails with attachments in Go.
Forked from github.com/scorredoira/email
, with these modifications:
- RFC-2047-compliant splitting of attachment filenames and subject
- Can send mail via
/usr/sbin/sendmail
Install
go get github.com/casipw/email
Usage
package main
import (
"github.com/casipw/email"
"net/mail"
"net/smtp"
)
func main() {
m := email.NewMessage("Subject", "Body")
m.From = mail.Address{Name: "Sender", Address: "[email protected]"}
m.To = []string{"[email protected]"}
if err := m.Attach("file.pdf"); err != nil {
panic(err)
}
// pass it to sendmail
email.Sendmail("[email protected]", m)
// or send it via SMTP
auth := smtp.PlainAuth("", "[email protected]", "mypassword", "smtp.example.com")
if err := email.Send("smtp.example.com:587", auth, m); err != nil {
panic(err)
}
}
Html
// use the html constructor
m := email.NewHTMLMessage("Hi", "this is the body")
Inline
// use Inline to display the attachment inline.
if err := m.Inline("main.go"); err != nil {
log.Fatal(err)
}