Skip to content

Golang mail library with interchangeable backends

License

Notifications You must be signed in to change notification settings

fastbill/go-mail

Repository files navigation

go-mail Build Status GoDoc

Package mail provides an easy interface with interchangable backends. Pull requests for additional mail providers are very welcome.

Implementation roadmap

Example usage

package main

import (
	"github.com/fastbill/go-mail/v3"
	"github.com/fastbill/go-mail/v3/mandrill"
)

func main() {
	// Create and ping Mandrill mailer.
	mandrillMailer := mandrill.MustNew("https://mandrillapp.com/api/1.0/", "my-token")
	err := mandrillMailer.Ping()
	if err != nil {
		panic(err)
	}

	// Create template mailer.
	templateMailer := MustNewStandardTemplateMailer(mandrillMailer, "/templates/*.tmpl")

	// Configure email for sending.
	template := &Template{
		Data: map[string]interface{}{
			"Foo": 1234,
		},
		TextPath: "hello.text.tmpl",
		HTMLPath: "hello.html.tmpl",
	}
	config := &Config{
		From:    &Address{Name: "FastBill GmbH", Email: "[email protected]"},
		To:      []Address{Address{Name: "Info", Email: "[email protected]"}},
		Subject: "Hello world",
		Options: &mandrill.Options{
			Important: true,
		},
	}

	// Send email.
	if err := templateMailer.Send(template, config); err != nil {
		panic(err)
	}
}