Robust and flexible email library for Go
The email
package is designed to be simple to use, but flexible enough so as not to be restrictive. The goal is to provide an email interface for humans.
The email
package currently supports the following:
- From, To, Bcc, and Cc fields
- Email addresses in both "[email protected]" and "First Last <[email protected]>" format
- Text and HTML Message Body
- Attachments
- Read Receipts
- Custom headers
- More to come!
go get github.com/jordan-wright/email
Note: Requires go version 1.1 and above
e := email.NewEmail()
e.From = "Jordan Wright <[email protected]>"
e.To = []string{"[email protected]"}
e.Bcc = []string{"[email protected]"}
e.Cc = []string{"[email protected]"}
e.Subject = "Awesome Subject"
e.Text = []byte("Text Body is, of course, supported!")
e.HTML = []byte("<h1>Fancy HTML is supported, too!</h1>")
e.Send("smtp.gmail.com:587", smtp.PlainAuth("", "[email protected]", "password123", "smtp.gmail.com"))
You can also create an email directly by creating a struct as follows:
e := &email.Email {
To: []string{"[email protected]"},
From: "Jordan Wright <[email protected]>",
Subject: "Awesome Subject",
Text: []byte("Text Body is, of course, supported!"),
HTML: []byte("<h1>Fancy HTML is supported, too!</h1>"),
Headers: textproto.MIMEHeader{},
}
e := NewEmail()
e.AttachFile("test.txt")
http://godoc.org/github.com/jordan-wright/email
Sections inspired by the handy gophermail project.
I'd like to thank all the contributors and maintainers of this package.
A special thanks goes out to Jed Denlea jeddenlea for his numerous contributions and optimizations.