Skip to content

XotoX1337/tinymail

Repository files navigation

Go Reference Go Report Card

tinymail

tinymail is a small package to easily send simple emails in go.

Download

go get github.com/XotoX1337/tinymail

Features

  • SMTP Authentification
  • Email with text body
  • Email from Template as String or File
  • Attachments

Examples

Text Email

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 success

Email from Template

import "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 success

Email with Attachments

import "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

About

small library to easily send smtp emails (text, html) in go

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages