mailer

package module
v0.0.0-...-7bfd630 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 28, 2015 License: MIT Imports: 5 Imported by: 0

README

Mailer

Send mail with golang via AWS SES.

The package expects AWS_ACCESS_KEY_ID and AWS_SECRET_KEY to be set.

Templates are parsed with text/template.

// First we register a template
welcometpl := `Welcome {{.to}}`
tpl := &mailer.Template{
	Name: "welcome",
	Subject: "Welcome",
	Body: welcometpl,
	From: "contact@acme.com",
}
mailer.RegisterTemplate(tpl)

// Create a `mailer.Mail` object
m := mailer.New().Tpl("welcome", nil).To("thomas.sileo@gmail.com")
// m.Payload() returns JSON if you want to send the payload in a message queue

// Actually send the mail
if err := mailer.Send(m); err != nil {
	panic(err)
}

TODO

  • Add a basic worker (chan *Mail)
  • HTML template support?
  • Loads email template from a YAML file?

Documentation

Overview

Package mailer implements utility function to send mail.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterTemplate

func RegisterTemplate(tpl *Template)

func Send

func Send(m *Mail) error

Send actually send the mail

Types

type Mail

type Mail struct {
	// contains filtered or unexported fields
}

func New

func New() *Mail

func (*Mail) Payload

func (m *Mail) Payload() []byte

Payload serialize the payload in JSON, can be sent to a message queue for processing

func (*Mail) To

func (m *Mail) To(email string) *Mail

func (*Mail) Tpl

func (m *Mail) Tpl(name string, data map[string]interface{}) *Mail

type Template

type Template struct {
	From    string
	Name    string
	Body    string
	Subject string
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL