emailsender

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2021 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

emailsender package provides email senders.

Index

Constants

This section is empty.

Variables

View Source
var (
	WrongEmailValue = errors.New("Wrong email value (missing recipient or nil template)")
)

Functions

This section is empty.

Types

type BatchSender

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

BatchSender is a sender that stores emails in a queue to send them asynchronously in batch. Emails from the queue are sent while the connections is opened. The connection is opened once the number of waiting emails reach a threshold or when an email is in the queue for at least a given duration. The connection is closed as soon as there is no waiting email in the queue.

func StartBatchSender

func StartBatchSender(options BatchSenderOptions) (sender *BatchSender, err error)

StartBatchSender creates, starts and returns a new BatchSender.

func (*BatchSender) Close

func (self *BatchSender) Close() error

Close asks the sender to send all the emails in the queue and then to stop the background goroutine.

func (*BatchSender) Send

func (self *BatchSender) Send(email Email) error

Send adds an email to the queue.

type BatchSenderOptions

type BatchSenderOptions struct {
	MinBatchLen int
	MaxDelay    string // string representation of a duration
	Sender      string // email address
	SMTP        string // host:port
}

BatchSenderOptions records the options for the batch sender. An email is sent by the batch sender either if there are at least (MinBatchLen - 1) other emails waiting for being sent, or if the email is wainting to be sent for at least MaxDelay.

type DirectSender

type DirectSender struct {
	Sender string // email address
	SMTP   string // host:port
	// contains filtered or unexported fields
}

DirectSender is a sender that directly sends emails to an SMTP server. The connection to the server is left open for multiple emails to be send in one session.

func (*DirectSender) Close

func (self *DirectSender) Close() error

func (*DirectSender) Quit

func (self *DirectSender) Quit() error

Quit closes the currently opened connection, if any. It should be called as soon as there is no email to send.

func (*DirectSender) Send

func (self *DirectSender) Send(email Email) (err error)

Send sends an email to the SMTP server. It opens a new connection if needed, otherwise it uses the previously opened connection.

type Email

type Email struct {
	To   []string
	Tmpl *template.Template
	Data interface{}
}

Email represents an email to be sent.

The real email (both its header and its body) is constructed by the Sender by applying the provided template to the provided data.

type Sender

type Sender interface {

	// Send asks the sender to send an email. The email may be kept in memory and sent later.
	// Hence nil return value does not mean the email has been sent.
	Send(email Email) error

	// Close closes the sender. This may result in retained email to be sent.
	Close() error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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