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

      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

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

      func (SmtpEmailerConfig) EmailerID

      func (cfg SmtpEmailerConfig) EmailerID() string

      func (SmtpEmailerConfig) EmailerType

      func (cfg SmtpEmailerConfig) EmailerType() string

      func (*SmtpEmailerConfig) UnmarshalJSON

      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

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