An easy way to send emails with attachments in Go
go get github.com/scorredoira/email
package email_test
import (
"log"
"net/mail"
"net/smtp"
"github.com/scorredoira/email"
)
func Example() {
// compose the message
m := email.NewMessage("Hi", "this is the body")
m.From = mail.Address{Name: "From", Address: "[email protected]"}
m.To = []string{"[email protected]"}
// add attachments
if err := m.Attach("email.go"); err != nil {
log.Fatal(err)
}
// send it
auth := smtp.PlainAuth("", "[email protected]", "pwd", "smtp.zoho.com")
if err := email.Send("smtp.zoho.com:587", auth, m); err != nil {
log.Fatal(err)
}
}
// use the html constructor
m := email.NewHTMLMessage("Hi", "this is the body")
// use Inline to display the attachment inline.
if err := m.Inline("main.go"); err != nil {
log.Fatal(err)
}