tinymail is a small package to easily send simple emails in go.
go get github.com/XotoX1337/tinymail
- SMTP Authentification
- Email with text body
- Email from Template as String or File
- Attachments
import "github.com/XotoX1337/tinymail"
opts := tinymail.MailerOpts{
User: "username",
Password: "password",
Host: "host",
Port: 587
}
mailer := tinymail.New(opts)
msg := tinymail.FromString("this is a example")
msg.SetFrom("[email protected]")
msg.SetTo("[email protected]")
msg.SetSubject("TestWriteMessage")
err := mailer.SetMessage(msg).Send()
if err != nil {
fmt.Println(err)
}
# send successimport "github.com/XotoX1337/tinymail"
opts := tinymail.MailerOpts{
User: "username",
Password: "password",
Host: "host",
Port: 587
}
mailer := tinymail.New(opts)
msg := tinymail.FromTemplateFile(path/to/template/file)
msg.SetFrom("[email protected]")
msg.SetTo("[email protected]")
msg.SetSubject("TestWriteMessage")
err := mailer.SetMessage(msg).Send()
if err != nil {
fmt.Println(err)
}
# send successimport "github.com/XotoX1337/tinymail"
opts := tinymail.MailerOpts{
User: "username",
Password: "password",
Host: "host",
Port: 587
}
mailer := tinymail.New(opts)
msg := tinymail.FromString("attachment example")
msg.SetFrom("[email protected]")
msg.SetTo("[email protected]")
msg.SetSubject("TestWriteMessage")
msg.Attach(path/to/file, path/to/second/file, ...)
err := mailer.SetMessage(msg).Send()
if err != nil {
fmt.Println(err)
}
# send success