Back to godoc.org

Package mailer

v1.6.1
Latest Go to latest

The latest major version is .

Published: Jul 9, 2019 | License: AGPL-3.0 | Module: github.com/EngineerIG/cells

Overview

Package mailer acts a central mail server for the application.

It implements various types of communication with actual mail servers (sendmail, smtp, sendgrid API) and a simple queue mechanism to avoid spamming these servers.

Index

Constants

const (
	// MaxSendRetries defines number of retries in case of connection failure.
	MaxSendRetries = 5
)

func NewGomailMessage

func NewGomailMessage(email *mailer.Mail) (*gomail.Message, error)

NewGomailMessage prepares a new Message to be sent.

type BoltQueue

type BoltQueue struct {

	// For Testing purpose : delete file after closing
	DeleteOnClose bool
	// Path to the DB file
	DbPath string
	// contains filtered or unexported fields
}

BoltQueue defines a queue for the mails backed by a Bolt DB.

func NewBoltQueue

func NewBoltQueue(fileName string, deleteOnClose ...bool) (*BoltQueue, error)

NewBoltQueue creates a Bolt DB if necessary.

func (*BoltQueue) Close

func (b *BoltQueue) Close() error

Close closes the DB and delete corresponding file if deleteOnClose flag as been set on creation.

func (*BoltQueue) Consume

func (b *BoltQueue) Consume(sendHandler func(email *mailer.Mail) error) error

Consume acquires the lock and send mails that are in the queue by batches, sending at most 100 mails by batch.

func (*BoltQueue) Push

func (b *BoltQueue) Push(email *mailer.Mail) error

Push acquires the lock and add a mail to be sent in the queue.

type Queue

type Queue interface {
	Push(email *mailer.Mail) error
	Consume(func(email *mailer.Mail) error) error
	Close() error
}

func GetQueue

func GetQueue(ctx context.Context, t string, conf common.ConfigValues) Queue

type SendGrid

type SendGrid struct {
	ApiKey string
}

SendGrid is a passerelle to Sendgrid API. It holds the application API Key.

func (*SendGrid) Check

func (s *SendGrid) Check(ctx context.Context) error

func (*SendGrid) Configure

func (s *SendGrid) Configure(ctx context.Context, config config.Map) error

Configure expects a valid sendgrid API key.

func (*SendGrid) Send

func (s *SendGrid) Send(email *mailer.Mail) error

Send performs the real code to the sendgrid API.

type Sender

type Sender interface {
	Configure(ctx context.Context, conf config.Map) error
	Send(email *mailer.Mail) error
	Check(ctx context.Context) error
}

func GetSender

func GetSender(t string, conf config.Map) (Sender, error)

type Sendmail

type Sendmail struct {
	BinPath string
}

func (*Sendmail) Check

func (s *Sendmail) Check(ctx context.Context) error

func (*Sendmail) Configure

func (s *Sendmail) Configure(ctx context.Context, config config.Map) error

func (*Sendmail) Send

func (d *Sendmail) Send(email *mailer.Mail) error

type Smtp

type Smtp struct {
	User               string
	Password           string
	Host               string
	Port               int
	InsecureSkipVerify bool
}

func (*Smtp) Check

func (gm *Smtp) Check(ctx context.Context) error

func (*Smtp) Configure

func (gm *Smtp) Configure(ctx context.Context, conf config.Map) error

func (*Smtp) Send

func (gm *Smtp) Send(email *mailer.Mail) error

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier