postdog

package module
v0.16.1 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// BeforeSend is the Hook that's called before a mail is sent.
	BeforeSend = Hook(iota + 1)
	// AfterSend is the Hook that's called after a mail has been sent.
	AfterSend
)

Variables

View Source
var (
	// ErrNoTransport means no transport is configured.
	ErrNoTransport = errors.New("no transport")
	// ErrUnconfiguredTransport means a transport with a specific name is not configured.
	ErrUnconfiguredTransport = errors.New("unconfigured transport")
)

Functions

func SendError

func SendError(ctx context.Context) error

SendError returns the error of the last (*Dog).Send() call that has been made using ctx.

func SendTime added in v0.9.0

func SendTime(ctx context.Context) time.Time

SendTime returns the time of the last (*Dog).Send() call that has been made using ctx.

Types

type Dog added in v0.8.0

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

A Dog can send mails through one of multiple configured transports.

func New

func New(opts ...Option) *Dog

New returns a new *Dog.

func (*Dog) Send added in v0.8.0

func (dog *Dog) Send(ctx context.Context, m Mail, opts ...send.Option) error

Send sends the given mail through the default transport.

A different transport can be specified with the Use() option:

dog.Send(context.TODO(), m, postdog.Use("transport-name"))

If the Use() option is used and no transport with the specified name has been registered, Send() will return ErrUnconfiguredTransport.

If the Use() option is not used, the default transport will be used instead. The default transport is automatically the first transport that has been registered and can be overriden by calling dog.Use("transport-name"). If there's no default transport available, Send() will return ErrNoTransport.

func (*Dog) SendConfig added in v0.9.2

func (dog *Dog) SendConfig(ctx context.Context, m Mail, cfg send.Config) error

SendConfig does the same as Send() but accepts a send.Config instead of send.Options.

func (*Dog) Transport added in v0.8.0

func (dog *Dog) Transport(name string) (Transport, error)

Transport returns either the transport with the given name or an ErrUnconfiguredTransport error.

func (*Dog) Use added in v0.8.0

func (dog *Dog) Use(transport string)

Use sets the default transport.

type Hook added in v0.8.0

type Hook uint8

A Hook is a hook point.

type Listener added in v0.8.0

type Listener interface {
	Handle(context.Context, Hook, Mail)
}

Listener is a callback for a Hook.

type ListenerFunc added in v0.8.0

type ListenerFunc func(context.Context, Hook, Mail)

ListenerFunc allows functions to be used as Listeners.

func (ListenerFunc) Handle added in v0.8.0

func (lis ListenerFunc) Handle(ctx context.Context, h Hook, m Mail)

Handle calls lis(ctx, h, m).

type Mail added in v0.8.0

type Mail interface {
	// From returns the sender of the mail.
	From() mail.Address
	// Recipients returns the recipients of the mail.
	Recipients() []mail.Address
	// RFC returns the RFC 5322 body / data of the mail.
	RFC() string
}

A Mail provides the sender, recipients and the mail body as defined in RFC 5322.

func ApplyMiddleware added in v0.12.2

func ApplyMiddleware(ctx context.Context, m Mail, mw ...Middleware) (context.Context, Mail, error)

ApplyMiddleware applies the Middleware mw on the Mail m.

type Middleware

type Middleware interface {
	Handle(context.Context, Mail, NextMiddleware) (Mail, error)
}

Middleware is called on every Send(), allowing manipulation of mails before they are passed to the Transport.

type MiddlewareFunc

type MiddlewareFunc func(context.Context, Mail, NextMiddleware) (Mail, error)

A MiddlewareFunc allows functions to be used as Middleware.

func (MiddlewareFunc) Handle

func (mw MiddlewareFunc) Handle(ctx context.Context, m Mail, fn NextMiddleware) (Mail, error)

Handle calls mw() with the given arguments.

type NextMiddleware added in v0.10.1

type NextMiddleware func(context.Context, Mail) (Mail, error)

NextMiddleware wraps the next function that Middlewares receive as the last parameter.

type Option

type Option interface {
	Apply(*Dog)
}

Option is a *Dog option.

type OptionFunc added in v0.8.0

type OptionFunc func(*Dog)

OptionFunc allows functions to be used as Options.

func WithHook added in v0.8.0

func WithHook(h Hook, l Listener) OptionFunc

WithHook returns an OptionFunc that adds Listener l for Hook h to a *Dog.

func WithMiddleware

func WithMiddleware(mws ...Middleware) OptionFunc

WithMiddleware returns an OptionFunc that adds the middleware mws to a *Dog.

func WithMiddlewareFunc added in v0.8.0

func WithMiddlewareFunc(mws ...MiddlewareFunc) OptionFunc

WithMiddlewareFunc returns an OptionFunc that adds the middleware mws to a *Dog.

func WithRateLimiter added in v0.8.0

func WithRateLimiter(rl Waiter) OptionFunc

WithRateLimiter returns an OptionFunc that adds a middleware to a *Dog.

The middleware will call rl.Wait() for every mail that's sent.

func WithTransport added in v0.8.0

func WithTransport(name string, tr Transport) OptionFunc

WithTransport returns an OptionFunc that adds the transport tr with the name in name to a *Dog.

func (OptionFunc) Apply added in v0.8.0

func (opt OptionFunc) Apply(d *Dog)

Apply calls opt(d).

type Plugin

type Plugin []Option

A Plugin is a collection of Options.

func (Plugin) Apply added in v0.8.0

func (p Plugin) Apply(d *Dog)

Apply calls opt(d) for every Option opt in p.

type Transport

type Transport interface {
	Send(context.Context, Mail) error
}

A Transport is responsible for actually sending mails.

type Waiter added in v0.8.0

type Waiter interface {
	// Wait should block until the next mail can be sent.
	Wait(context.Context) error
}

A Waiter implements rate limiting.

Directories

Path Synopsis
mocks
Package mock_config is a generated GoMock package.
Package mock_config is a generated GoMock package.
internal
rfc
rfc/mocks
Package mock_rfc is a generated GoMock package.
Package mock_rfc is a generated GoMock package.
Package mock_postdog is a generated GoMock package.
Package mock_postdog is a generated GoMock package.
plugin
archive/mocks
Package mock_archive is a generated GoMock package.
Package mock_archive is a generated GoMock package.
mocks
Package mock_queue is a generated GoMock package.
Package mock_queue is a generated GoMock package.
transport
gmail/mocks
Package mock_gmail is a generated GoMock package.
Package mock_gmail is a generated GoMock package.
nop
smtp/mocks
Package mock_smtp is a generated GoMock package.
Package mock_smtp is a generated GoMock package.

Jump to

Keyboard shortcuts

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