modulepackage
0.0.0-20191113075454-e396096c6c94
Repository: https://github.com/mattes/go-mail.git
Documentation: pkg.go.dev
# README
go-mail 
- Load template files from disk or embedded store.
- Preview rendered template files with example data in browser with go-mail-preview tool.
- Automatically inlines CSS.
- Powered by Go's html/template and text/template engine.
- Supports markdown to HTML parsing inside template.
- Use provider to send an email.
Usage
import (
"github.com/mattes/go-mail"
"github.com/mattes/go-mail/provider/mailgun"
)
// load templates
tpl, err := mail.NewTemplates(mail.FilesFromLocalDir("./templates"))
// create mail envelope
m := mail.New()
m.Subject = "Advice to self"
m.To("Mattes", "[email protected]")
m.Template(tpl, "simple", mail.Vars{
"Body": "no ice cream after midnight",
})
// send email with mailgun (or any other provider)
p, err := mailgun.New("mailgun-domain", "mailgun-key")
err = p.Send(m)
Templates
Structure
Emails can have a HTML and/or text body. Templates are recognized by their file extension.
my-template.html -> used for html body, processed with Go's html/template engine
my-template.txt -> used for text body, processed with Go's text/template engine
my-template.example.yaml -> used for preview
Embed templates into Go binary
To embed templates into your Go binary, you can use a tool like go.rice.
Install go.rice first:
go get github.com/GeertJohan/go.rice
go get github.com/GeertJohan/go.rice/rice
Update your go code:
//go:generate rice embed-go
var MyTemplates = rice.MustFindBox("./path/to/templates")
Run go generate
to generate the embedded file. See files.go and
files_test.go for an example.
Nice templates
There is a couple of tested email templates available, please have a look at:
# Packages
No description provided by the author
# Functions
Func adds a function to the template's function map.
Funcs adds the elements of the argument map to the template's function map.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Delims sets the delimiters.
Simple is a simple default template ready to be used.
# Constants
No description provided by the author
i.e.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Type aliases
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author