Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mattes/go-mail
Render and send emails with Go
https://github.com/mattes/go-mail
css-inliner emails go golang mail markdown templates
Last synced: 25 days ago
JSON representation
Render and send emails with Go
- Host: GitHub
- URL: https://github.com/mattes/go-mail
- Owner: mattes
- License: mit
- Created: 2019-11-12T08:19:26.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2019-11-13T07:54:58.000Z (about 5 years ago)
- Last Synced: 2024-10-04T17:38:53.537Z (about 1 month ago)
- Topics: css-inliner, emails, go, golang, mail, markdown, templates
- Language: Go
- Homepage:
- Size: 850 KB
- Stars: 9
- Watchers: 2
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-mail [![GoDoc](https://godoc.org/github.com/mattes/go-mail?status.svg)](https://godoc.org/github.com/mattes/go-mail)
* Load template files from disk or embedded store.
* Preview rendered template files with example data in browser with [go-mail-preview tool](./go-mail-preview).
* Automatically [inlines CSS](https://github.com/aymerick/douceur).
* Powered by Go's [html/template](https://golang.org/pkg/html/template/) and [text/template](https://golang.org/pkg/text/template/) engine.
* Supports [markdown](https://github.com/yuin/goldmark) to HTML parsing inside template.
* Use [provider](./provider) to send an email.## Usage
```go
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](https://github.com/GeertJohan/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
//go:generate rice embed-govar MyTemplates = rice.MustFindBox("./path/to/templates")
```Run `go generate` to generate the embedded file. See [files.go](./files.go) and
[files_test.go](./files_test.go) for an example.### Nice templates
There is a couple of tested email templates available, please have a look at:
* https://github.com/wildbit/postmark-templates
* https://github.com/mailgun/transactional-email-templates
* https://github.com/leemunroe/responsive-html-email-template
* https://github.com/leemunroe/amp-email-templates