email

package
v6.3.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2018 License: MIT Imports: 5 Imported by: 1

Documentation

Overview

Package email allows for log messages to be sent via email.

Example

simple email

package main

import (
    "github.com/go-playground/log"
    "github.com/go-playground/log/handlers/email"
)

func main() {

    email := email.New("smtp.gmail.com", 587, "username", "password", "from@email.com", []string{"to@email.com"})

    log.AddHandler(email, log.WarnLevel, log.AlertLevel, log.PanicLevel)

    log.WithField("omg", "something went wrong").Alert("ALERT!")
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Email

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

Email is an instance of the email logger

func New

func New(host string, port int, username string, password string, from string, to []string) *Email

New returns a new instance of the email logger

func (*Email) From

func (email *Email) From() string

From returns the Email's From address

func (*Email) Log

func (email *Email) Log(e log.Entry)

Log handles the log entry

func (*Email) SetEmailConfig

func (email *Email) SetEmailConfig(host string, port int, username string, password string, from string, to []string)

SetEmailConfig allows updating of the email config in flight and is thread safe.

func (*Email) SetEnabled

func (email *Email) SetEnabled(enabled bool)

SetEnabled enables or disables the email handler sending emails

func (*Email) SetFormatFunc

func (email *Email) SetFormatFunc(fn FormatFunc)

SetFormatFunc sets FormatFunc each worker will call to get a Formatter func

func (*Email) SetTemplate

func (email *Email) SetTemplate(htmlTemplate string)

SetTemplate sets Email's html template to be used for email body

func (*Email) SetTimestampFormat

func (email *Email) SetTimestampFormat(format string)

SetTimestampFormat sets Email's timestamp output format Default is : "2006-01-02T15:04:05.000000000Z07:00"

func (*Email) Template

func (email *Email) Template() *template.Template

Template returns the Email's template

func (*Email) To

func (email *Email) To() []string

To returns the Email's To address

type FormatFunc

type FormatFunc func(email *Email) Formatter

FormatFunc is the function that the workers use to create a new Formatter per worker allowing reusable go routine safe variable to be used within your Formatter function.

type Formatter

type Formatter func(e log.Entry) *gomail.Message

Formatter is the function used to format the Email entry

Jump to

Keyboard shortcuts

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