email

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2016 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FakeEmailerType = "fake"
)
View Source
const (
	MailgunEmailerType = "mailgun"
)
View Source
const (
	SmtpEmailerType = "smtp"
)

Variables

View Source
var (
	ErrorNoTemplate = errors.New("No HTML or Text template found for template name.")
)

Functions

func RegisterEmailerConfigType

func RegisterEmailerConfigType(emailerType string, fn NewEmailerConfigFunc)

Types

type Emailer

type Emailer interface {
	// SendMail queues an email to be sent to 1 or more recipients.
	// At least one of "text" or "html" must not be blank. If text is blank, but
	// html is not, then an html-only email should be sent and vice-versal.
	SendMail(subject, text, html string, to ...string) error
}

Emailer is an object that sends emails.

type EmailerConfig

type EmailerConfig interface {
	EmailerID() string
	EmailerType() string

	// Because emailers can either be configured through command line flags or through
	// JSON configs, we need a way to set the fromAddr when initializing the emailer.
	//
	// Values passed in the JSON config should override this value. Supplying neither
	// should result in an error.
	Emailer(fromAddress string) (Emailer, error)
}

func NewEmailerConfigFromFile

func NewEmailerConfigFromFile(loc string) (EmailerConfig, error)

func NewEmailerConfigFromType

func NewEmailerConfigFromType(emailerType string) (EmailerConfig, error)

type FakeEmailer

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

FakeEmailer is an Emailer that writes emails to stdout. Should only be used in development.

func (FakeEmailer) SendMail

func (f FakeEmailer) SendMail(subject, text, html string, to ...string) error

type FakeEmailerConfig

type FakeEmailerConfig struct {
	FromAddr string `json:"from"`
}

func (FakeEmailerConfig) Emailer

func (cfg FakeEmailerConfig) Emailer(fromAddr string) (Emailer, error)

func (FakeEmailerConfig) EmailerID

func (cfg FakeEmailerConfig) EmailerID() string

func (FakeEmailerConfig) EmailerType

func (cfg FakeEmailerConfig) EmailerType() string

type MailgunEmailerConfig

type MailgunEmailerConfig struct {
	FromAddr      string `json:"from"`
	PrivateAPIKey string `json:"privateAPIKey"`
	PublicAPIKey  string `json:"publicAPIKey"`
	Domain        string `json:"domain"`
}

func (MailgunEmailerConfig) Emailer

func (cfg MailgunEmailerConfig) Emailer(fromAddr string) (Emailer, error)

func (MailgunEmailerConfig) EmailerID

func (cfg MailgunEmailerConfig) EmailerID() string

func (MailgunEmailerConfig) EmailerType

func (cfg MailgunEmailerConfig) EmailerType() string

func (*MailgunEmailerConfig) UnmarshalJSON

func (cfg *MailgunEmailerConfig) UnmarshalJSON(data []byte) error

type NewEmailerConfigFunc

type NewEmailerConfigFunc func() EmailerConfig

type SmtpEmailerConfig added in v0.2.0

type SmtpEmailerConfig struct {
	Host     string `json:"host"`
	Username string `json:"username"`
	Password string `json:"password"`
	FromAddr string `json:"from"`

	// OPTIONAL: If empty and host is of form "host:port" just use that. For backward
	// compatibility do not change this.
	Port int `json:"port"`

	// DEPRICATED: If "username" and "password" are provided, use them.
	Auth string `json:"auth"`
}

func (SmtpEmailerConfig) Emailer added in v0.2.0

func (cfg SmtpEmailerConfig) Emailer(fromAddr string) (Emailer, error)

func (SmtpEmailerConfig) EmailerID added in v0.2.0

func (cfg SmtpEmailerConfig) EmailerID() string

func (SmtpEmailerConfig) EmailerType added in v0.2.0

func (cfg SmtpEmailerConfig) EmailerType() string

func (*SmtpEmailerConfig) UnmarshalJSON added in v0.2.0

func (cfg *SmtpEmailerConfig) UnmarshalJSON(data []byte) error

type TemplatizedEmailer

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

TemplatizedEmailer sends emails based on templates, using any Emailer.

func NewTemplatizedEmailerFromGlobs

func NewTemplatizedEmailerFromGlobs(textGlob, htmlGlob string, emailer Emailer, fromAddr string) (*TemplatizedEmailer, error)

NewTemplatizedEmailerFromGlobs creates a new TemplatizedEmailer, parsing the templates found in the given filepattern globs.

func NewTemplatizedEmailerFromTemplates

func NewTemplatizedEmailerFromTemplates(textTemplates *template.Template, htmlTemplates *htmltemplate.Template, emailer Emailer, fromAddr string) *TemplatizedEmailer

NewTemplatizedEmailerFromTemplates creates a new TemplatizedEmailer, given root text and html templates.

func (*TemplatizedEmailer) SendMail

func (t *TemplatizedEmailer) SendMail(subject, tplName string, data map[string]interface{}, to string) error

SendMail queues an email to be sent to a recipient. SendMail has similar semantics to Emailer.SendMail, except that you provide the template names you want to base the message on instead of the actual text. "to", "from" and "subject" will be added into the data map regardless of if they are used.

func (*TemplatizedEmailer) SetGlobalContext added in v0.2.0

func (t *TemplatizedEmailer) SetGlobalContext(ctx map[string]interface{})

Jump to

Keyboard shortcuts

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